以文本方式查看主题

-  Foxtable(狐表)  (http://www.foxtable.com/bbs/index.asp)
--  专家坐堂  (http://www.foxtable.com/bbs/list.asp?boardid=2)
----  [求助]多空格一次替换为单空格  (http://www.foxtable.com/bbs/dispbbs.asp?boardid=2&id=177045)

--  作者:2900819580
--  发布时间:2022/5/7 14:39:00
--  [求助]多空格一次替换为单空格
Dim str As String = dt.DataRows(5)("代码")
Dim str1 As String  = str.Replace(vbcrlf," ").Replace(vbtab," ").Replace("      "," ").Replace("     "," ").Replace("  "," ")

老师,像这种内容里,有换行,还有不定空格的,如何一次过将不定长的空格换成只有一个空格呀?

--  作者:有点蓝
--  发布时间:2022/5/7 14:47:00
--  
Dim str As String = dt.DataRows(5)("代码")
str  = str.Replace(vbcrlf," ")
Dim pattern As String = "[\\s]+"
str = System.Text.RegularExpressions.Regex.Replace(str , pattern ," ")
Output.Show(str)