string VB.NET - 从字符串中删除一个字符
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5398356/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
VB.NET - Remove a characters from a String
提问by Jonathan Rioux
I have this string:
我有这个字符串:
Dim stringToCleanUp As String = "bon;jour"
Dim characterToRemove As String = ";"
I want a function who removes the ';' character like this:
我想要一个删除“;”的函数 性格是这样的:
Function RemoveCharacter(ByVal stringToCleanUp, ByVal characterToRemove)
...
End Function
What would be the function ?
功能是什么?
ANSWER:
回答:
Dim cleanString As String = Replace(stringToCleanUp, characterToRemove, "")
Great, Thanks!
万分感谢!
采纳答案by rlb.usa
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
Here's more information about VB's Replace function
这里有更多关于VB 的替换功能的信息
回答by Oded
回答by Hunter Wright
The string
class's Replace
method can also be used to remove multiple characters from a string:
本string
类的Replace
方法也可以用来去除从字符串的多个字符:
Dim newstring As String
newstring = oldstring.Replace(",", "").Replace(";", "")
回答by Travis
You can use the string.replace method
您可以使用字符串.replace 方法
string.replace("character to be removed", "character to be replaced with")
string.replace("要删除的字符", "要替换的字符")
Dim strName As String
strName.Replace("[", "")