A string type variable can be considered a read-only group of variables of type char, so that each string can be accessed using the following syntax:
string mystring="A string"; Char mychar=mystring[1];
However, you cannot assign values to individual strings in this way. In order to obtain a writable char array, you can use the following code, which uses the ToCharArray () command of the array variable:
string mystring="A string"; Char [] Mychars = Mystring.tochararray ();
You can then work with the char array in a standard way. You can also use strings in a foreach loop. For example:
foreach ( in myString) { Console.WriteLine ("[0]", character);}
As with arrays, you can also use Mystring.length to get the number of elements, which gives the number of characters in the string, for example:
string myString = console.readline (); Console.WriteLine ("", mystring.length);
The basic processing techniques for other strings are used with this <string>. The ToCharArray () command uses the command in a similar format. Two simple but very effective command <string> ToLower () and <string>. ToUpper (). They can convert strings to uppercase and lowercase, respectively. Consider the following scenario: To check a response from a user, such as a string yes. If you can convert a user-entered string to lowercase, you can also check the string yes, yes, yes, and so on.
namespaceconsoleapplication1{classProgram {Static voidMain (string[] args) { stringmystring="This is a test."; //separating each string in a space will get its substring, that is, an array containing a single word. Char[] seperator={' '}; string[] mywords; Mywords=Mystring.split (seperator); //Use the Foreach loop to iterate through the words in the array and write the words to the console foreach(stringWordinchmywords) {Console.WriteLine ("{0}", Word); } console.readkey (); } }}// This// is//a//test.
Use <string>. Split () Converts a string into a string array, separating it from the specified position. These locations are in the form of a char array, with only one element, the space character, in the example above.
C # programming (9_string)