我对LEN功能有一些奇怪的问题。我的输入是字符串" ......" LEN返回长度为2.我不知道为什么会发生这种情况。有什么建议? 我使用的代码是:
Function replaceCharWith(ByVal str As String, ByVal chToReplace As String, ByVal ch As String) As String
For i = 1 To Len(str)
If Mid(str, i, 1) = chToReplace Then
replaceCharWith = replaceCharWith & ch
Else
replaceCharWith = replaceCharWith & Mid(str, i, 1)
End If
Next
End Function
Sub dotsToSlashes()
Dim c As Range
For Each c In Selection
c = replaceCharWith(c, ".", "/")
Next
End Sub
感谢。
答案 0 :(得分:6)
我怀疑你的字符串不是“......”而是“......”。这是HORIZONTAL ELLIPSIS Unicode x2026的2倍。如果自动更正选项是默认值,Excel将自动替换... ...
参见示例:
Sub HorizontalEllipsesTest()
s = "......"
MsgBox Len(s)
s = ChrW(8230) & ChrW(8230) 'x2026 = 8230
MsgBox s
MsgBox Len(s)
End Sub