Kal*_*ani 7 c# removing-whitespace
如何使用c#删除中间的空间?我有string name="My Test String",我需要"MyTestString"使用c#的字符串输出.请帮我.
Sai*_*ala 36
写如下
name = name.Replace(" ","");
Run Code Online (Sandbox Code Playgroud)
using System;
using System.Text.RegularExpressions;
class TestProgram
{
static string RemoveSpaces(string value)
{
return Regex.Replace(value, @"\s+", " ");
}
static void Main()
{
string value = "Sunil Tanaji Chavan";
Console.WriteLine(RemoveSpaces(value));
value = "Sunil Tanaji\r\nChavan";
Console.WriteLine(RemoveSpaces(value));
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
29115 次 |
| 最近记录: |