none
C#开发关于string.Split函数的问题 RRS feed

  • 问题

  • string date = "12 21 34";要将其用Split函数将其分成“12”,“21”,“34”三个字符串并赋值给一个string[]  t。应该怎么使用,我老用不对,求能人赐教!

    2013年12月30日 3:34

答案

  • string[] t = date.Split(" ");

    t[0]就是12

    t[1]就是21

    t[2]就是34

    2013年12月30日 4:30
  • string date = "12 21 34";
                string[] result = date.Split(' ');
                foreach (string s in result)
                {
                    Console.WriteLine(s);
                }

    看一下Split方法的定义就知道了。

    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    2013年12月31日 5:18
    版主

全部回复

  • string[] t = date.Split(" ");

    t[0]就是12

    t[1]就是21

    t[2]就是34

    2013年12月30日 4:30
  • string date = "12 21 34";
                string[] result = date.Split(' ');
                foreach (string s in result)
                {
                    Console.WriteLine(s);
                }

    看一下Split方法的定义就知道了。

    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    2013年12月31日 5:18
    版主