本帖最后由 zhlin3415058 于 2011-03-08 14:20:04 编辑

解决方案 »

  1.   

    只要你要取的值是连续的没有空格隔开的...你都可以Split(' ');分割字符串..然后要用的时候Trim()
      

  2.   


    商户编号  308350149000080                           清算日期  20101227      生成日期    20101229  
                                                                                                          第     1页  
    终端编号   交易时间          账号         发卡行        交易金额  交易手续费        结算金额    系统检索号  跟踪号  渠道  交易类型
    ────  ─────  ─────────  ───  ───────  ─────  ───────  ──────  ───  ──  ────
    30808013 1228105552 6229023431678105    03090000       41,200.00     -412.00       40,788.00 000001000019  137133  pos        消费          终端编号          交易笔数            交易金额            手续费            结算金额
              30808013                 1           41,200.00           -412.00           40,788.00
                小计                   1           41,200.00           -412.00           40,788.00          交易类型          交易笔数            交易金额            手续费            结算金额
                消费                   1           41,200.00           -412.00           40,788.00
                小计                   1           41,200.00           -412.00           40,788.00
      

  3.   

    可能没有表述清楚...假设你的这么一行string str="11102342  0702155306      622909116759559617";数据...你要取的是11102342、0702155306和622909116759559617
    你也已做的是string[] strs=str.Split(' ');
    //
    int cnt=strs.Length;
    for(int i=0;i<cnt;i++){strs[i]=strs[i].Trim();}
      

  4.   

    我说的都是笨办法..呵呵..string[] strs=str.Split(' ');
    //
    int cnt=strs.Length;
    List<string> list=new List<string>();
    for(int i=0;i<cnt;i++)
    {
         if(!string.IsNullOrEmpty(strs[i].Trim()))
         {
             list.Add(strs[i].Trim());
         }
    }
      

  5.   

    这时候list里保存的都是有效值...没有空值了...不过还有一个方法用正则...但是鄙人对正则不甚了解..所以就不献丑了..也不知道正则适不适合这样的场合
      

  6.   

    是有点笨,但是有效呵呵不过,为什么不用正则表达式先去除中间的空格呢?效率会高很多。//去字符串中所有(此方法无法除首尾空格)空格,可以先用aaa.Trim()去除首位空格然后去除中间空格
                    string[] aaa = System.Text.RegularExpressions.Regex.Split(text, @"[ ]+");                //去字符串中所有(此方法无法除首尾空格)空格
                    //@"[ ]+"                //[]中为删除的可选字符
      

  7.   

    示例:using System;
    using System.Text;
    class test
    {
    static void Main()
    {
                   string text="你好         zhlin3415058  能 否  解   决             你的问题";//首尾中有空格,个数不确定
                    text=text.Trim();//删除首尾空格
                    //去字符串中所有(此方法无法除首尾空格)空格
                    string[] aaa = System.Text.RegularExpressions.Regex.Split(text, @"[ ]+");
                    //去字符串中所有(此方法无法除首尾空格)空格
                    //@"[ ]+"
                    //[]中为删除的可选字符
                    text = aaa[0];
                    for (int i = 1; i < aaa.Length; i++)
                    {
                           text = text + " " + aaa[i];
                    }
    Console.WriteLine(text);
    }
    }
    程序输出:
    你好 zhlin3415058 能 否 解 决 你的问题
      

  8.   

    然后你就可以使用Split函数来分隔空格提取字符串了OK,结贴了!
      

  9.   

    受该兄台点拨...Split的一个重载方法str.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries);呵呵..可以省去我上面的循环....
      

  10.   


    // listValue[10] 要处理的字符串值 空字符串过滤1:
    listValue[10].Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries)空字符串过滤2:
    System.Text.RegularExpressions.Regex.Split(listValue[10], @"[ ]+")两种方法都很简便~