2
我正在使用此功能刪除所有假定的特殊字符,但仍然很少有特殊字符,例如「Ø」或「é」,並且所有類似字符仍然存在如何在下面給出的函數中處理此問題。刪除Excel中的特殊字符
我的想法是,創建一個像MyStr這樣的特殊字符的字符串並將其刪除。
請建議。
Function ReplaceSplChars(TempStr As String) As String
Dim counter As Long, Position As Long
Dim MyStr As String, SplStr As String
MyStr = " [email protected]"
Position = 1
For counter = 1 To Len(TempStr)
SplStr = Mid(LCase(TempStr), Position, 1)
If Not InStr(MyStr, SplStr) > 0 Then
If SplStr = "-" Or SplStr = "_" Or SplStr = "'" Or SplStr = "/" Or SplStr = "," Then
TempStr = Replace(TempStr, SplStr, " ", , 1)
SplCharCount = SplCharCount + 1
Position = Position + 1
Else
TempStr = Replace(TempStr, SplStr, "", , 1)
SplCharCount = SplCharCount + 1
End If
Else
Position = Position + 1
End If
Next counter
ReplaceSplChars = TempStr
End Function
尼斯使用正則表達式。但請注意,字符類括號是多餘的。 –
是的。開始一場負面比賽並沒有完全放鬆。 – brettdj
你好,謝謝你的回覆。 –