Presentation is loading. Please wait.

Presentation is loading. Please wait.

String Manipulation.

Similar presentations


Presentation on theme: "String Manipulation."— Presentation transcript:

1 String Manipulation

2 Assigning String Literals
string s1; s1=“abc”; OR string s1= “abc”;

3 Copying Strings string s1=“abc”; string s2 = s1; OR
string s2= string.Copy(s1);

4 Concatenating Strings
string s1=“abc”; string s2=“xyz” string s3 = s1 + s2; OR string s3= string.Concat(s1,s2);

5 Reading from Keyboard string s = Console.ReadLine();

6 The ToString() Method int no = 123; string nstr =no.ToString(); OR
string nstr =Convert.ToString(no);

7 Verbatim Strings Start with Symbol @ OR
string s1 “C:\myfolder\string.cs”; OR string s1 = “C:\\myfolder\\string.cs”;

8 Regular vs Verbatim Strings
Console.WriteLine("This string contains a newline\n and a tab\t and an escaped backslash\\"); string displays as is. No newlines\n, tabs\t or backslash-escapes\\.");

9 Types of C# String C# Strings Immutable Mutable System.String
StringBuilder Regular Expressions

10 Immutable String Methods
String Class Compare() CompareTo() Concat() Copy() CopyTo() Endswith() Equals()

11 Immutable String Methods
IndexOf() Insert() Join() LastIndexOf() PadLeft() PadRight()

12 Immutable String Methods
Remove() Replace() Split() StartsWith() Substring() ToLower() ToUpper()

13 Immutable String Methods
Trim() TrimEnd() TrimStart()

14 Mutable Strings Methods
StringBuider Class Append() AppendFormat() EnsureCapacity() Insert() Remove() Replace()

15 Regular Expressions Regular Expressions provides tool for searching and manipulating a large text . Namespace: System.Text.RegularExpressions

16 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

17 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);


Download ppt "String Manipulation."

Similar presentations


Ads by Google