|
发表于 2024-10-28 08:37
来自手机
|
显示全部楼层
Cavan2022 发表于 2024-10-27 20:48
[\s] 等价于 [ \f\n\r\t\v],这样不行.
估计是字符集的问题,VBA运行时,网页复制的空白字符,在程序运行时 ...
Sub RemoveNonBreakingSpaces()
Dim inputString As String
Dim regex As Object
Dim cleanedString As String
' Example input string with non-breaking spaces
inputString = "This is an example string with non-breaking space: " & ChrW(&H00A0) & "and here."
' Create a new RegExp object
Set regex = CreateObject("VBScript.RegExp")
' Set the pattern to match the non-breaking space character
regex.Pattern = ChrW(&H00A0)
regex.Global = True ' Replace all instances
' Perform the replacement
cleanedString = regex.Replace(inputString, " ")
' Output the result
Debug.Print cleanedString
End Sub
|
|