Aside from programming syntax rules, programming is like processing strings.
C # string story:
1. char
Char c = 'a'; If char c = "a"; c = 'abc' is incorrect. Single quotes, double quotes, and strings
2. string
String str = "hello ";
The str string value is hello and the length is 5. It is different from the C language here, And the '\ 0 Terminator '.
3. Take the characters in the string
Char c = str [0]; // c = h;
Note that the subscript is out of bounds.
Print every character in the output string.
string str="hello";int size=str.length;for(int i=0; i<size; i++){ Console.WriteLine(str[i]);}
4. Changing and changing strings
650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131228/20340920B-0.png "title =" qqpinyin unnamed .png "data-pinit =" registered "/>
Verify this process:
String str1 = "hello"; // str10 points to the string pointed to by str1, rather than str1, even if str1 points to another string, and, // str10 is not affected string str10 = str1; str1 = "world"; Console. writeLine (str1); Console. writeLine (str10 );
The output result is:
World
Hello
As described here, the initial intention of str10 cannot be changed when str1 is suspected of being in love.
5. string segmentation
String [] Split (param char [] separator );
public static void Main(string [] args) { string ip="192.168.1.0"; string [] strArray=ip.Split('.'); foreach(string str in strArray) { Console.WriteLine(str); } Console.ReadKey(); }
650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131228/2034091964-1.png "title =" 1.png" data-pinit = "registered"/>
Use '.' to separate the IP address string.
Method of overloading Split:
String stringSplit = "today is very easy to get busy. Today's weather is good. Don't go to work today"; string [] strSplitArray = stringSplit. split (new String [] {"today"}, StringSplitOptions. removeEmptyEntries); foreach (string str in strSplitArray) {Console. writeLine (str );}
Use strings to separate strings.
The printed result is:
Very easy and busy
Good weather
Off duty
6. String replacement method
String stringSplit = "today is very easy to get busy. Today's weather is good, today is not going to work"; string newString = stringSplit. Replace ("today ","**");
Replace "today".
For example, some sensitive vocabulary processing methods in Website forums should be replaced with strings.
This article is from the "Ajax girl" blog!