C# 有像 Java 那样的 String Tokenizer 吗? [英] Does C# have a String Tokenizer like Java's?
本文介绍了C# 有像 Java 那样的 String Tokenizer 吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在做简单的字符串输入解析,我需要一个字符串标记器.我是 C# 的新手,但已经编写了 Java,C# 应该有一个字符串标记器似乎很自然.可以?它在哪里?我如何使用它?
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?
推荐答案
您可以使用 String.Split 方法.
class ExampleClass
{
public ExampleClass()
{
string exampleString = "there is a cat";
// Split string on spaces. This will separate all the words in a string
string[] words = exampleString.Split(' ');
foreach (string word in words)
{
Console.WriteLine(word);
// there
// is
// a
// cat
}
}
}
有关详细信息,请参阅 Sam Allen 关于在 c# 中拆分字符串的文章(性能,正则表达式)
For more information see Sam Allen's article about splitting strings in c# (Performance, Regex)
这篇关于C# 有像 Java 那样的 String Tokenizer 吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文