[英]VB.NET - Remove a characters from a String
我有這個字符串:
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, "")
十分感謝!
String
類有一個Replace
方法可以做到這一點。
Dim clean as String
clean = myString.Replace(",", "")
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
這里有關於VB的Replace功能的更多信息
string
類的Replace
方法也可用於從字符串中刪除多個字符:
Dim newstring As String
newstring = oldstring.Replace(",", "").Replace(";", "")
您可以使用字符串 .replace方法
string .replace(“ 要刪除的字符 ”,“ 要替換的字符 ”)
Dim strName As String
strName.Replace("[", "")
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.