Len函数返回不正确的结果
我有一个LEN函数的一个奇怪的问题。 我的input是string“……”,LEN返回的长度为2.我不知道为什么会发生这种情况。 有什么build议么? 我使用的代码是:
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
谢谢。
我怀疑你的string不是“……”,而是“……”。 这是HORIZONTAL ELLIPSIS Unicode x2026的2倍。 如果“自动更正选项”是默认选项,则Excel将自动replace…。
看例子:
Sub HorizontalEllipsesTest() s = "......" MsgBox Len(s) s = ChrW(8230) & ChrW(8230) 'x2026 = 8230 MsgBox s MsgBox Len(s) End Sub