Today I ran into this problem while helping a customer import the information from a txt file into a database. Because the number of spaces between two strings in the customer's txt file is uncertain, there is no way to use the split function to split, and the last way I came up with is to convert the consecutive spaces into a space, and then use split to split, which is easy to do.
The principle used here is: use regular expressions, so the file should be referenced
using System.Text.RegularExpressions; (Move the mouse over the code, four icons will appear at the top of the code, the first is to view the source code, the second is to copy the code, the third is to print the code, and the fourth is help) Suppose the contents of the string are str="A B C D E F"; str = new System.Text.RegularExpressions.Regex("[\\s]+"). Replace(str, " "); (Move the mouse over the code, four icons will appear at the top of the code, the first is to view the source code, the second is to copy the code, the third is to print the code, and the fourth is help) That's it, put the str output to see if it's A B C D E F.
|