如何拆分字符串?

时间:2011-07-19 09:34:52

标签: c# regex string

在以下示例中,

/*----------------------// kvkbl jk//bv klb /* /*gkljbgflkjbncviogf*/

如何获取/**/之间的字符串?

2 个答案:

答案 0 :(得分:1)

看看这个tutorial

using System;

class Program
{
    static void Main()
    {
        string s = "/*there*/ is a cat";
        string s = "User name (sales)";
        int start = s.IndexOf("/*");
        int end = s.IndexOf(")*/")
        string result = s.substring(start, end - start -1)
        //result contains "there"
    }
}

答案 1 :(得分:-1)

string s = "there is a cat";
    //
    // Split string on spaces.
    // ... This will separate all the words.
    //
    string[] words = s.Split(' ');
    foreach (string word in words)
    {
        Console.WriteLine(word);
    }



   //Output 
     there
     is
     a
     cat