






















Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!























Processing and Manipulating Text Using the .NET String Class
string s = "Hello, C#"; string s = "Hello" + " " + "C#";
string str = "Hello, C#"; char ch = str[2]; // OK str[2] = 'a'; // Error! string greeting = "你好"; // (lí-hó) Taiwanese
string greet = "Hello, "; string name = "John"; string result = string.Concat(greet, name); Console.WriteLine(result); //"Hello, John" string text = "Hello, "; text += "John"; //"Hello, John" string text = "Hello" + ", " + "world!"; //"Hello, world!"
string[] words = Console.ReadLine().Split(); string result = ""; foreach (string word in words) { int repeatTimes = word.Length; for (int i = 0; i < repeatTimes; i++) result += word; } Console.WriteLine(result);
string fruits = "banana, apple, kiwi, banana, apple"; Console.WriteLine(fruits.LastIndexOf("banana")); // Console.WriteLine(fruits.LastIndexOf("orange")); //- 1 string fruits = "banana, apple, kiwi, banana, apple"; Console.WriteLine(fruits.IndexOf("banana")); // Console.WriteLine(fruits.IndexOf("orange")); //- 1
ice kicegiceiceb kgb abc tcabctqw tctqw key keytextkey text word wordawordbwordc abc
▪ Split a string by given separator
string text = "Hello, [email protected], you have been using [email protected] in your registration"; string[] words = text.Split(", "); //words[]: //"Hello" //"[email protected]" //"you have been using [email protected] in your registration"
▪ Split can be used with multiple separators
char[] separators = new char[] { ' ', ',', '.' }; string text = "Hello, I am John."; string[] words = text.Split(separators); //"Hello", "", "I", "am", "John", ""
▪ Replace(match, replacement) – replaces all occurrences ▪ The result is a new string (strings are immutable)
string text = "Hello, [email protected], you have been using [email protected] in your registration."; string replacedText = text .Replace("[email protected]", "[email protected]"); Console.WriteLine(replacedText); //Output: //Hello, [email protected], you have been using [email protected] in your registration.
Linux, Windows It is not Linux, it is GNU/Linux. Linux is merely the kernel, while GNU adds the functionality...