我有这个字符串:
Dim stringToCleanUp As String = "bon;jour"
Dim characterToRemove As String = ";"
我想要一个删除';'的函数像这样的人物:
Function RemoveCharacter(ByVal stringToCleanUp, ByVal characterToRemove)
...
End Function
功能是什么?
解答:
Dim cleanString As String = Replace(stringToCleanUp, characterToRemove, "")
太好了,谢谢!
答案 0 :(得分:16)
String
类有一个Replace
方法可以做到这一点。
Dim clean as String
clean = myString.Replace(",", "")
答案 1 :(得分:12)
Function RemoveCharacter(ByVal stringToCleanUp, ByVal characterToRemove)
' replace the target with nothing
' Replace() returns a new String and does not modify the current one
Return stringToCleanUp.Replace(characterToRemove, "")
End Function
的更多信息
答案 2 :(得分:4)
string
类的Replace
方法也可用于从字符串中删除多个字符:
Dim newstring As String
newstring = oldstring.Replace(",", "").Replace(";", "")
答案 3 :(得分:0)
您可以使用字符串 .replace方法
string .replace(" 要删除的字符"," 字符将替换为 &#34)
Dim strName As String
strName.Replace("[", "")