--------------------编程问答--------------------
恩人在哪里。。。
--------------------编程问答--------------------
string a = "a,b,c,d,,e,,,空格空格空格...换行....省略";
string [] b = Regex.Split(a,"\r\n",RegexOptions.IgnoreCase);
string c = "";
foreach (var item in b)
{
c += item.Trim() + "\r\n";
}
--------------------编程问答--------------------
string[] lines = File.ReadAllLines("1.txt");
List<string> lineList = new List<string>();
foreach (string line in lines)
{
lineList.Add(line.TrimEnd(' '));
}
lineList.RemoveAt(lineList.Count-1);
File.WriteAllLines("2.txt", lineList.ToArray());
--------------------编程问答--------------------
string s = @"asdfa 32 weriu435u
asdrwerf 234
aswedf 234
assafdf 234";
s = System.Text.RegularExpressions.Regex.Replace(s.Replace("\r\n", "겕"), @"\s+겕|겕\s+", "겕");
s=s.Replace("겕", "\r\n");
s = System.Text.RegularExpressions.Regex.Replace(s.Replace("\r\n", "겕"), @"\s+겕|겕\s+", "겕");
s = System.Text.RegularExpressions.Regex.Replace(s, @"겕+", "겕").Trim('겕');
s = s.Replace("겕", "\r\n");
用正则吧,把换行替换成特殊符号,再替换前后空格,最后把换行替换回来
还要替换空行
--------------------编程问答--------------------
string str = "你的字符串";
if (string.IsNullOrEmpty(str.Trim()) == false)
{
string[] rows = str.Split('\n');
int colIndex = 0;
int r = 0;
foreach (var item in rows)
{
string[] cols = item.Split('\t');
if (!string.IsNullOrEmpty(item))
{
int c = 1;
foreach (var col in cols)
{
string colStr = col.TrimEnd('\r').Trim();
switch (colIndex + c)
{
case 1:
if (string.IsNullOrEmpty(colStr) == false)
{
s = System.Text.RegularExpressions.Regex.Replace(s.Replace("\r\n", "겕"), @"\s+겕|겕\s+", "겕");
s = System.Text.RegularExpressions.Regex.Replace(s, @"겕+", "겕").Trim('겕');
s = s.Replace("겕", "\r\n");
用正则吧,把换行替换成特殊符号,再替换前后空格,最后把换行替换回来
还要替换空行
请问怎么文本中的空行呢
s = System.Text.RegularExpressions.Regex.Replace(s, @"겕+", "겕").Trim('겕');这个已经是替换空行了。
--------------------编程问答--------------------
--------------------编程问答--------------------