日期:2014-05-17  浏览次数:20817 次

字串碰到空白時縮短與下一個值的距離為三個空白
想请教TXT内有几行值为
1234456789______123_______456
1234456789________123________456
底线为空白(实际并无底线)
我想要让它变成
1234456789___123___456
1234456789___123___456

该如何下手呢......恳请高手相助!

------解决方案--------------------
C# code
            string str = "1234456789         123     456";
            Regex reg = new Regex(@"\s+",RegexOptions.IgnorePatternWhitespace);
            str=reg.Replace(str, " ");

------解决方案--------------------
C# code
        string filename = @"c:\test.txt";
        string s = File.ReadAllText(filename);
        string r = Regex.Replace(s, @"[\t ]+", "  ");
        File.WriteAllText(filename, r);

------解决方案--------------------
C# code
string str="1234456789";
str=str.Replace("5","5 ");