I'm doing simple string input parsing and I am in need of a string tokenizer. I am new to C# but have programmed Java, and it seems natural that C# should have a string tokenizer. Does it? Where is it? How do I use it?
相关问题
- Sorting 3 numbers without branching [closed]
- Graphics.DrawImage() - Throws out of memory except
- Why am I getting UnauthorizedAccessException on th
- Correctly parse PDF paragraphs with Python
- 求获取指定qq 资料的方法
Or
The similar to Java's method is:
where
string
- the text you need to splitpattern
- string type pattern, what is splitting the textThe split method of a string is what you need. In fact the tokenizer class in Java is deprecated in favor of Java's string split method.
If you're trying to do something like splitting command line arguments in a .NET Console app, you're going to have issues because .NET is either broken or is trying to be clever (which means it's as good as broken). I needed to be able to split arguments by the space character, preserving any literals that were quoted so they didn't get split in the middle. This is the code I wrote to do the job:
If you are using C# 3.5 you could write an extension method to System.String that does the splitting you need. You then can then use syntax:
More info and a useful example from MS here http://msdn.microsoft.com/en-us/library/bb383977.aspx
use
Regex.Split(string,"#|#");