我正在做简单的字符串输入解析,我需要一个字符串标记器。我是 C# 新手,但已经编写过 Java 程序,因此 C# 应该有一个字符串标记生成器似乎很自然。可以?它在哪里?我该如何使用它?
你可以使用String.Split 方法 http://msdn.microsoft.com/en-us/library/system.string.split.aspx.
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# 中分割字符串的文章 http://www.dotnetperls.com/split(性能、正则表达式)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)