New*_*art 13 c# regex whitespace
有任何想法吗?
我的程序是一个文件验证实用程序,我必须读取一个格式文件,然后用一个空格解析每一行.但显然,编写格式文件的人可能会使用制表符,或2个空格,或任何形式的空格,我正在寻找一些代码来做到这一点.我试过这个:
public static string RemoveWhitespace(this string line)
{
try
{
return new Regex(@"\s*").Replace(line, " ");
}
catch (Exception)
{
return line;
}
}
Run Code Online (Sandbox Code Playgroud)
我认为这是错的.
救命!
Sac*_*hag 36
你可以这样做 -
System.Text.RegularExpressions.Regex.Replace(str,@"\s+"," ");
Run Code Online (Sandbox Code Playgroud)
str
你的字符串在哪里
归档时间: |
|
查看次数: |
16410 次 |
最近记录: |