In C#, a string is a sequence of characters, represented by the string keyword. Here are some of the most commonly used methods for working with strings:
string str = "Hello, World!";
int len = str.Length; // len = 13
string str = "Hello, World!";
string substr = str.Substring(7, 5); // substr = "World"
string str = "Hello, World!";
int index = str.IndexOf("World"); // index = 7
string str = "Hello, World!";
string newStr = str.Replace("World", "Universe"); // newStr = "Hello, Universe!"
string str = "Hello, World!";
string newStr = str.ToLower(); // newStr = "hello, world!"
string str = "Hello, World!";
string newStr = str.ToUpper(); // newStr = "HELLO, WORLD!"
string str1 = "Hello, ";
string str2 = "World!";
string newStr = String.Concat(str1, str2); // newStr = "Hello, World!"
string str = "Hello, {0}!";
string name = "John";
string newStr = String.Format(str, name); // newStr = "Hello, John!"
These are just a few of the many methods provided by the String class in C#. The exact method you need will depend on the specific program you’re writing.
Learners TV is a website that is designed to educate users and provide instructional material on particular subjects and topics.