回答
Dim text = "My name is Anas Fares"
Dim newText = System.Text.RegularExpressions.Regex.Replace(text, "[ ]{2,}", " ")
或者,如果你想摆脱标签,换行符等等等等等等
Dim text = "My name is " & Environment.NewLine & " Anas Fares"
Dim newText = System.Text.RegularExpressions.Regex.Replace(text, "\s+", " ")
这是最好的:D – 2012-03-01 03:59:37
+1对于每个答案。一切正确:D – 2012-03-01 04:00:00
@JimThio:谢谢。很高兴我帮了忙。 – LeftyX 2012-03-01 09:43:53
只需将做一个字符串替换上了双白色的空间,一个空格:
Dim str = "Lorem Ipsum Dolar"
str = str.replace(" ", " ")
return str 'Lorem Ipsum Dolar
但你仍然可以使用相同的正则表达式在VB.NET从JavaScript代码中使用你的链接。本文介绍正是这样做的一种方式:
http://msdn.microsoft.com/en-us/library/xwewhkd1.aspx
Dim input As String = "This is text with far too much " + _
"whitespace."
Dim pattern As String = "\s+"
Dim replacement As String = " "
Dim rgx As New Regex(pattern)
Dim result As String = rgx.Replace(input, replacement)
Console.WriteLine("Original String: {0}", input)
Console.WriteLine("Replacement String: {0}", result)
A这一个直接转换将是:
Dim r As Regex = New Regex("\s{2,}") 'or " {2,}" or "[ ]{2,}", depending on if you want whitespace, or just spaces.
Dim stringWithDoubleSpaces As String = "this is a double spaced string"
Dim stringWithSingleSpaces As String = r.Replace(stringWithDoubleSpaces, " ")
- 1. 用RegEx去除空格
- 2. JAVA Mail从主题中去除双空格
- 3. 如何使用正则表达式去除双空白字符?
- 4. VB.NET;去除位图
- 5. 如何去除双斜线使用SED
- 6. C++如何去除双引号字符
- 7. 如何在vb.net中使用ValidationExpression时排除空格
- 8. 如何从Python DataFrame中去除空格在这个例子中
- 9. 如何在R中的字符串结尾删除双空格?
- 10. 除去空间
- 11. 制表符,空格和数字去除
- 12. 去除PHP中变量内的空格
- 13. 去除查询MySQL的空格
- 14. 去掉空格
- 15. 去掉空格
- 16. 去掉空格
- 17. 去掉空格
- 18. 去掉空格
- 19. 除去双反斜线
- 20. 双回路去除物品
- 21. 如何去除网格图中的空白?
- 22. 如何去除TCL中字符串中的空格?
- 23. 如何去除数字字符之间的空格字符?
- 24. 如何去除这些讨厌多余的空格
- 25. 如何去除表格中的白色空白?
- 26. 如何去除<xsl:attribute>标签内的空格?
- 27. 空间去除在MySQL
- 28. 如何使用sed删除字符串中的双空格
- 29. 如何从字符串中删除双字符和空格
- 30. 如何编码空间去除
'str = Regex.Replace(str,“\ s +”,“”);' - 这是你想要的吗? – fardjad 2012-02-29 11:08:40