Jon*_*oux 18 vb.net string visual-studio-2010
我有这个字符串:
Dim stringToCleanUp As String = "bon;jour"
Dim characterToRemove As String = ";"
Run Code Online (Sandbox Code Playgroud)
我想要一个删除';'的函数 像这样的人物:
Function RemoveCharacter(ByVal stringToCleanUp, ByVal characterToRemove)
...
End Function
Run Code Online (Sandbox Code Playgroud)
功能是什么?
回答:
Dim cleanString As String = Replace(stringToCleanUp, characterToRemove, "")
Run Code Online (Sandbox Code Playgroud)
十分感谢!
Ode*_*ded 17
该String班有一个Replace会做的方法.
Dim clean as String
clean = myString.Replace(",", "")
Run Code Online (Sandbox Code Playgroud)
rlb*_*usa 13
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
Run Code Online (Sandbox Code Playgroud)
这里有关于VB的Replace功能的更多信息
本string类的Replace方法也可以用来去除从字符串的多个字符:
Dim newstring As String
newstring = oldstring.Replace(",", "").Replace(";", "")
Run Code Online (Sandbox Code Playgroud)