string s = "113.733270 21.953484\r\n 113.744410 21.954060\r\n 113.745770 21.952154\r\n 113.745770 21.948023\r\n";
题目如上,去掉每组数据间的空格,但是每组数据里的两个数据间的空格不能去掉,\r\n保留
题目如上,去掉每组数据间的空格,但是每组数据里的两个数据间的空格不能去掉,\r\n保留
string newStr = "";
for(int i = 0; i<strs.lenght;i++)
{
newStr+ = strs[i].replace(" ","");
}
using System.Text.RegularExpressions
引用
s = s.Replace("\r\n ","\r\n");
strTest = strTest.Replace( " ","" );
private string DeleteSpace(string str)
{
string s = string.Empty;
if (str.Length > 0)
{
string[] word = str.Split(new char[] { ' ' });
foreach (string temp in word)
{
s = s + temp;
}
}
return s;
}
113.733270 21.953484\r\n 113.744410 21.954060:\r\n后面有不确定的空格数
string[] strs = Regex.Split(s,"\r\n ");
string newStr = "";
for (int i = 0; i < strs.Length; i++)
{
newStr += strs[i].Trim()+'\n';
}
s=System.Text.RegularExpressions.Regex.Replace(s, @"\r\n[ ]+", "\r\n");
字符串里的\要转义
temp = Regex.Replace(temp, @"\s", "");
Console.WriteLine(temp);//输出
"113.73327021.953484113.74441021.954060113.74577021.952154113.74577021.948023"
temp = Regex.Replace(temp, @"[\s][^\r\n[ ]]*[ ]", "");