Sometimes we use string [] lines = system. Io. file. readalllines (@ "C:/root. ini", encoding. Default); to obtain information in the text.
However, because the text file may be nonstandard, the retrieved string array contains spaces.
However, sometimes Strings need to be compared or output, so these spaces need to be processed.
Case 1: If the string array contains spaces
For example, a [0] = "AA"; A [1] = "; A [2] =" 321 ";
Solution: When retrieving the string array, use removeemptyentries to process the blank string,
Example: String [] Split (char [] separator, stringsplitoptions.Removeemptyentries)
Case 2: The obtained string has spaces at both ends.
For example, a [0] = "AAA"; A [1] = "ad"; A [2] = "DDD ";
Solution: We can use the trim method to solve this problem, traverse the entire array, or specify the element to use
Example: String S2 = A [0].Trim;
==============================================
The processing of strings in C # is very powerful. = A Lot Of functions ....
For more information about the split method, see msdn ---- split (Bilingual)
For more trim method reference: msdn ---- trim (http://msdn.microsoft.com/zh-cn/library/system.string.trim (vs.80). aspx)
My everybody space: http://www.renren.com/profile.do? Id = 252260104
My csdn space: http://student.csdn.net /? 1300560