String Manipulation
Assigning String Literals string s1; s1=“abc”; OR string s1= “abc”;
Copying Strings string s1=“abc”; string s2 = s1; OR string s2= string.Copy(s1);
Concatenating Strings string s1=“abc”; string s2=“xyz” string s3 = s1 + s2; OR string s3= string.Concat(s1,s2);
Reading from Keyboard string s = Console.ReadLine();
The ToString() Method int no = 123; string nstr =no.ToString(); OR string nstr =Convert.ToString(no);
Verbatim Strings Start with Symbol @ OR string s1 = @ “C:\myfolder\string.cs”; OR string s1 = “C:\\myfolder\\string.cs”;
Regular vs Verbatim Strings Console.WriteLine("This string contains a newline\n and a tab\t and an escaped backslash\\"); Console.WriteLine(@"This string displays as is. No newlines\n, tabs\t or backslash-escapes\\.");
Types of C# String C# Strings Immutable Mutable System.String StringBuilder Regular Expressions
Immutable String Methods String Class Compare() CompareTo() Concat() Copy() CopyTo() Endswith() Equals()
Immutable String Methods IndexOf() Insert() Join() LastIndexOf() PadLeft() PadRight()
Immutable String Methods Remove() Replace() Split() StartsWith() Substring() ToLower() ToUpper()
Immutable String Methods Trim() TrimEnd() TrimStart()
Mutable Strings Methods StringBuider Class Append() AppendFormat() EnsureCapacity() Insert() Remove() Replace()
Regular Expressions Regular Expressions provides tool for searching and manipulating a large text . Namespace: System.Text.RegularExpressions
Regular Expressions Pattern String (Literals, Metachar) “\bm” Meaning “\bm” Any Word beginning with m “er\b” Any Word ending with m “\BX\B” Any X in the middle of a word “\bm\S*er\b” Any word beginning with m and ending with er. “|,” Any word separated by a space or a comma
Arrays of Strings String [ ] itemArray=new String[3]; Example: String [ ] itemArray={“Java”, “C++”, “Csharp” }; Properties and Methods: itemArray.Length; Array.Sort(itemArray); Array.Reverse(itemArray);