在编写代码的工程中,我们发现经常有些莫名的错误。往往找很长时间,还是没有答案。有时就是因为一个符号而影响的。
由于中英文标点是不同的,经常在写代码的时候用中文代替了。或者有时我们需要的时中文标点,在输入的时候却出来英文。
下面的函数就是帮我们把字符串中的英文替换成中文标点。而中文标点替换英文标点自己下去慢慢参详了。
常规标点好办点,单引用与双引号有点困难
Private Function enTozhMark(ReplaceStr As String) As String
'把传递进来的字符串中的英文标点符号替换成中文标点符号
Const enStr As String = ",.?;:!()"
Const zhStr As String = ",。?;:!()"
Dim I As Byte, L As Integer, B As Boolean, N As Integer
enTozhMark = ReplaceStr
'替换常规标点符号
For I = 1 To 8
enTozhMark = Replace(enTozhMark, Mid(enStr, I, 1), Mid(zhStr, I, 1))
Next I
'替换双引号
N = 0: B = False
L = Len(enTozhMark)
For I = 1 To L
N = InStr(N + 1, enTozhMark, Chr(34))
If N <> 0 Then
I = N
If B = False Then
enTozhMark = Left(enTozhMark, N - 1) & "“" & Mid(enTozhMark, N + 1)
Else
enTozhMark = Left(enTozhMark, N - 1) & "”" & Mid(enTozhMark, N + 1)
End If
B = Not B
Else
Exit For
End If
Next I
'替换单引号
N = 0: B = False
For I = 1 To L
N = InStr(N + 1, enTozhMark, Chr(39))
If N <> 0 Then
I = N
If B = False Then
enTozhMark = Left(enTozhMark, N - 1) & "‘" & Mid(enTozhMark, N + 1)
Else
enTozhMark = Left(enTozhMark, N - 1) & "’" & Mid(enTozhMark, N + 1)
End If
B = Not B
Else
Exit For
End If
Next I
End Function