我是新手,刚从vc转行过来,请问个问题
有个文件,内容如下:
aaaa    男    26
bbb     女    23
ccc     男    24中间是tab分割读文件我已经做到了,用的ReadLine 读取了一行,按照以前c++的做法,我就可以使用sscanf来格式化这个数据,很快,姓名,性别,年龄就可以区分出来
请问,在C#里如何做到?

解决方案 »

  1.   

    可以用String的Split(new char[]{'tab符'});来分隔
      

  2.   


    using System;public class SplitTest {
        public static void Main() {        string words = "this is a list of words, with: a bit of punctuation.";        string [] split = words.Split(new Char [] {' ', ',', '.', ':'});        foreach (string s in split) {            if (s.Trim() != "")
                    Console.WriteLine(s);
            }
        }
    }
      

  3.   

    string ss="aaaa 男 26".Split(' ');
    string s1=ss[0]; //aaa
    string s2=ss[1]; //男 
    string s3=ss[2]; //26
      

  4.   

    string[] arr=File.ReadAllLines("");
    string[] arr=File.ReadAllText().Split(new Char [] {' ',','});