C#有一个字符串标记像Java的? [英] Does C# have a String Tokenizer like Java's?

查看:107
本文介绍了C#有一个字符串标记像Java的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在做简单的字符串输入解析和我需要一个字符串标记的。我是新来的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
        }
    }
}

有关详细信息,请参见山姆·艾伦的关于C#分割字符串(性能,正则表达式)的文章

For more information see Sam Allen's article about splitting strings in c# (Performance, Regex)

这篇关于C#有一个字符串标记像Java的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆