为什么我的空间不能修剪

这看起来很明显,直接,但不起作用。 我正在Excel VBA中工作。 我得到打开的Word应用程序,并从Word中的表中书签的位置提取文本。 那么麻烦就开始了。 结果string是5个字符(32)空格。 但无论我尝试什么,我都摆脱不了空间。 为什么这些空间不被修剪或更换?

Dim Wd As Word.Application Set Wd = GetObject(, "Word.Application") Dim doc As Word.Document 'Dim r As Word.Range 'Dim p As Word.Paragraph Dim tb As Word.Table Set doc = Wd.ActiveDocument Set tb = doc.Tables(1) 'tb.Select Dim Place As String Place = Trim(doc.Bookmarks("County").Range.Text) 'outputs length 5 Debug.Print Len(Place) 'this outputs 32 5 times so I know we have chr(32) and not something else Dim i As Integer For i = 1 To Len(Place) Debug.Print Asc(Mid(Place, i, 1)) Next 'try trim Place = Trim(Place) Debug.Print Len(Place) 'still 5 spaces 'try replace Dim s As String s = VBA.Replace(Place, Chr(32), "") Debug.Print Len(Place) 'still 5 spaces 

我的代码发生了什么?

可能是unicode空间,请考虑U2000 EN QUAD空白:

 x="W" & chrw(&h2000) & "W" ?x WW ?asc(mid(x,2,1)) 32 <= normalized ?ascw(mid(x,2,1)) 8192 <= true character 

所以用ascw检查char并用ascwreplace