mirror of
https://bitbucket.org/Mattrixwv/cstutorials.git
synced 2025-12-06 18:34:03 -05:00
Initial commit with a few examples
This commit is contained in:
41
StringManipulation.cs
Normal file
41
StringManipulation.cs
Normal file
@@ -0,0 +1,41 @@
|
||||
//C#/Tutorials/StringManipulation.cs
|
||||
//Matthew Ellison
|
||||
// Created: 07-29-20
|
||||
//Modified: 07-29-20
|
||||
//This has some simple string manipulation examples
|
||||
|
||||
|
||||
using System;
|
||||
|
||||
|
||||
namespace mee{
|
||||
public class StringManipulation{
|
||||
public static void Main(string[] args){
|
||||
string greeting = " Hello World ";
|
||||
Console.WriteLine($"[{greeting}]");
|
||||
string trimmedGreeting = "";
|
||||
//trimmedGreeting = greeting.TrimStart();
|
||||
Console.WriteLine($"[{trimmedGreeting}]");
|
||||
//trimmedGreeting = greeting.TrimEnd();
|
||||
Console.WriteLine($"[{trimmedGreeting}]");
|
||||
trimmedGreeting = greeting.Trim();
|
||||
Console.WriteLine($"[{trimmedGreeting}]");
|
||||
|
||||
//Find
|
||||
Console.WriteLine("\nFind:");
|
||||
string songLyrics = "You say goodbye, and I say hello";
|
||||
Console.WriteLine(songLyrics.Contains("goodbye"));
|
||||
Console.WriteLine(songLyrics.Contains("greetings"));
|
||||
Console.WriteLine(songLyrics.EndsWith("hello"));
|
||||
Console.WriteLine(songLyrics.EndsWith("goodbye"));
|
||||
|
||||
//Find and replace
|
||||
Console.WriteLine("\nFind and Replace:");
|
||||
Console.WriteLine(greeting.Trim());
|
||||
string newGreeting = greeting.Replace("Hello", "Greetings").Trim();
|
||||
Console.WriteLine(newGreeting);
|
||||
Console.WriteLine(newGreeting.ToLower());
|
||||
Console.WriteLine(newGreeting.ToUpper());
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user