Max*_*gal 0 excel vba excel-vba
我对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
Run Code Online (Sandbox Code Playgroud)
谢谢.
我怀疑你的字符串不是"......"而是"......".这是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
Run Code Online (Sandbox Code Playgroud)