string s = "val1 val2  val3 val4";
s = s.Replace("  "," ");
s = s.Replace(" ",",");

解决方案 »

  1.   

    http://dev.csdn.net/Develop/article/41/41245.shtm
      

  2.   

    TO:brightheroes(闭关|那一剑的风情) 
    会把字符串变成
    val1,val2,val3,val4
    val1,val,2,val3,val4
      

  3.   

    string s = @"val1 val2  val3 val4
    val1 val 2  val3 val4";
    s= Regex.Replace(s,@"[ ]+(?=[a-zA-Z])",",");
    Console.WriteLine(s);
      

  4.   

    谢谢思归,但这种方法只能对
    val1 val2  val3 val4
    val1 val 2  val3 val4进行处理,
    我的数据要比这个复杂了。具体的数据如下:
    group 1. proudtd  3 3 4
    group 1. proudt abc  3 3 4
    如果可以的话,请帮我设计一下。我在正则表达式里找了很久,都处理不了。
      

  5.   

    what will the output be?
      

  6.   

    输出成这个:
    group,1.,proudtd,3,3,4
    group,1.,proudt abc,3,3,4
      

  7.   

    what is the rule here? the last three are always numbers?  if there is no rule, then there is no way to do it
      

  8.   

    规则是各个内容是通过一个空格相隔的,但在proudtd  3和proudt abc  3之间是用两个空格相隔的,后面的数字是可变的。有可能是数字,也可能是文字。
    group 1. proudtd  3 3 4
    group 1. proudt abc  3 3 4
    group(1个空格)1.(1个空格)proudtd(两个空格)3(1个空格)3(1个空格)4
    group(1个空格)1.(1个空格)proudt abc(两个空格)3(1个空格)3(1个空格)4
      

  9.   

    看你的要求group(1个空格)1.(1个空格)proudtd(两个空格)3(1个空格)3(1个空格)4
                   ^^^^^^^^^^怎么知道这里要不要换成","group(1个空格)1.(1个空格)proudt abc(两个空格)3(1个空格)3(1个空格)4
      

  10.   

    呵呵,可能是我的描述不清楚。其实这些数据是有规律的,就是在
    group(1个空格)1.(1个空格)proudtd(两个空格)3(1个空格)3(1个空格)4
                             *******          *
    这两个数据之间是两个空格,其他的数据是之间是一个空格隔开。
    而在proudtd的数据是可能有存在空格,但只当是一个数据来处理。
      

  11.   

    is it always the string "proudtd"? is the number of records fixed each line?