2015-05-17 54 views
-1

我有有许多句子和句子中的每个字是一个文件,以数字+一个选项卡,然后两个标签,例如制表符,空格和数字去除

4[one tab]Sun[two tabs] 5 [one tab]is[two tabs] 6[one tabs] rising[two tabs] 

我用下面的代码,但先这是行不通的

string strLine = sr.ReadLine(); 
resultString = Regex.Replace(strLine, @"(|\t|\r?\n)\s\1+", " "); 

我需要出去把这样的“太阳升起”

回答

1

您可以使用

resultString = Regex.Replace(strLine, @"[\s\d]+", " "); 

用一个空格替换制表符,空格和位数。

0

这可能会帮助您:

using System.IO; 
using System; 
using System.Text.RegularExpressions; 

class Program 
{ 
    static void Main() 
    { 
     String strLine="4 Sun  5 is  6 rising"; 
     String resultString = Regex.Replace(strLine, @"\d\t", ""); 
     resultString= Regex.Replace(resultString, @"\t\t", " "); 
     Console.Write(resultString); 
    } 
} 
+0

非常感谢这两部作品 – Wahab

相关问题