public static void Space(ref string str)
{
//空格在字符串中所处在的位置
int index = str.IndexOf(' ');
if (index >= 0 && index <= str.Length - 1)
{
try
{
//分成前后两个部分进行字符串的缩减
string start = str.Substring(0, index).Trim();
string end = str.Substring(index + 1, (str.Length - index - 1)).Trim();
//递归处理前后端
Space(ref end);
str = start + end;
}
catch (Exception e)
{
throw e;
}
}
}
C#不用Replace()去掉字符串中的空格
最新推荐文章于 2022-03-20 15:26:01 发布