从字符串中删除空格在 c# 中不起作用 [英] Removing White spaces from string is not working in c#
本文介绍了从字符串中删除空格在 c# 中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试从字符串中删除空格,但它不起作用
I am trying to remove whitespaces from string but it is not working
string status = " 18820 Pacific Coast Highway
Malibu, CA 90265";
string status1 = status.Trim();
Console.Write(status1);
以上代码无效
预期输出:
18820 Pacific Coast Highway Malibu, CA 90265
推荐答案
Trim()
仅适用于字符串的开头和结尾.这应该有效:
Trim()
only works at the start and end of a string. This should work:
string status1 = Regex.Replace(status,@"\s+"," ").Trim();
这篇关于从字符串中删除空格在 c# 中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文