Professional Documents
Culture Documents
Lecture 8
Jawad Rafeeq
Jawadrafeeq@ciitvehari.edu.pk
Outline
C# String
• A string is represented by class System.String.
• The maximum size of String object in memory is 2GB or about 1
billion characters.
for (int counter = 0; counter < nameString.Length; counter++)
Console.WriteLine(nameString[counter]);
foreach(char i in nameString)
{
System.Console.Write(i);
}
How to make an Empty String
• string empStr = string.Empty;
• string empStr2 = "";
C# Strings built-in methods
Using String.Equals
• If both strings are equal, the method returns true; else returns false.
• string aa = "ascd";
• string bb = "ascd";
• bool r = string.Equals(aa, bb);
• if(r==true)
• System.Console.WriteLine("Both are Equal");
Using String.Equals (Ignorecase)
• If both strings are equal, the method returns true; else returns false.
• string aa = "ascd";
• string bb = “ASCD";
• bool r = string.Equals(aa, bb, StringComparison.OrdinalIgnoreCase);
• if(r==true)
• System.Console.WriteLine("Both are Equal");
Using String.Compare (Extra functionality)
• string str1 = "csharp";
• string str2 = "csharp";