用C#怎么在文本文档里提取我想要的东西!
我要实现如:是一些联系方式,我要在这些里面把手机号码和联系人写入数据库里面
怎么可以实现?或者把联系方式的所有项分类的写入数据库里对应的字段里?

解决方案 »

  1.   

    1.读文件
    StreamReader  reader  = new StreamReader( File.OpenRead( filePath ) ) ;
    try
    {
    strResult = reader.ReadLine() ;

    catch ( Exception exc) 
    {
    throw new Exception("指定的文件不可以读",exc);
    }
    2.分解字符串
    3. 写入数据库
      

  2.   

    如果格式排列好肯定是不行的
    要不就中间用空格隔开
    张三  aaaa   1234
    李四  bbbb   5678读一行出来
    再用空格来划分成数组
      

  3.   

    StreamReader sr = new StreamReader("Data.txt", System.Text.Encoding.Default);
    string content = sr.ReadToEnd();
    System.Text.RegularExpressions.Regex reg = new System.Text.RegularExpressions.Regex("\r\n");
    string[] arrContent = reg.Split(content);
      

  4.   

    张三  aaaa   1234
    李四  bbbb   5678只要文本是按这样格式的。为什么要用程序转化。。直接导入数据库(ACCESS)中。就可以了