c# - 如何清除字符串中的重复空格

标签 c# vb.net

dim a as string = "     wilcome      to  sa      WeCame    "

期望的结果:

"Wilcome to sa WeCame"

最佳答案

您可以使用System.Text.RegularExpressions.Regex.Replace

Dim a As String = "     wilcome      to  sa      WeCame    "
Dim cleanedString As String = Regex.Replace(a, "\s{2,}", " ").Trim()

关于c# - 如何清除字符串中的重复空格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21933320/

相关文章:

c# - Redis StackExchange 缓存性能

vb.net "if statement"包含加号

c# - 多个组合框的相同内容

c# - 如何使用可选参数从 C# 调用用 VB.NET 编写的方法

c - 尝试将 VB.NET 代码转换为 C 代码

c# - 如何根据用户在 ASP.NET 中另一个下拉列表中的选择禁用下拉列表项?

C# - 发送电子邮件 - STOREDRV.Submission.Exception :OutboundSpamException

c# - 使用 Property 从 List<string> 获取值

c# - C# 中的 Try-Catch 与 If 性能

.net - 在 VB.NET 中记录和重播引发的事件