比如下面某文本的多行字符串:"
one澳大利亚-墨尔本/one
two美国-加州/two
three法国-巴黎/three
"
问:
1.如何实现将第二行的字符附值给一个string的变量?
2.如何实现将one    /one 之间的字符付值给一个string的变量?

解决方案 »

  1.   

    1.如何实现将第二行的字符附值给一个string的变量?
    -------------------------------------------------using System;
    using System.Text.RegularExpressions;class Test
    {
      static void Main()
      {
        string s0 =
    @"
    one澳大利亚-墨尔本/one
    two美国-加州/two
    three法国-巴黎/three
    ";
        string [] split = Regex.Split(s0, @"\r\n");
        Console.WriteLine(split[1]);  // <------------ split[1]就是你所要的
      }
    }/* 程序输出:
    one澳大利亚-墨尔本/one
    */
      

  2.   

    using System;
    using System.Text.RegularExpressions;class Test
    {
      static void Main()
      {
        string s0 =
    @"
    one澳大利亚-墨尔本/one
    two美国-加州/two
    three法国-巴黎/three
    ";
        string [] split = Regex.Split(s0, @"\r\n");
        string s1 = split[1];                // <------- split[1]就是原字符串第2行
        Console.WriteLine(s1);
        Match m = Regex.Match(s1, @"one(.*)/one");
        string s2 = m.Groups[1].ToString();  // <------- Groups[1]就是one../one之间的
        Console.WriteLine(s2);
      }
    }/* 程序输出:
    one澳大利亚-墨尔本/one
    澳大利亚-墨尔本
    */