VB.NET - Remove a characters from a String

前端 未结 4 1670
小蘑菇
小蘑菇 2021-02-18 15:34

I have this string:

Dim stringToCleanUp As String = \"bon;jour\"
Dim characterToRemove As String = \";\"

I want a function who removes the \';\

相关标签:
4条回答
  • 2021-02-18 16:06

    You can use the string.replace method

    string.replace("character to be removed", "character to be replaced with")

    Dim strName As String
    strName.Replace("[", "")
    
    0 讨论(0)
  • 2021-02-18 16:09
    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

    0 讨论(0)
  • 2021-02-18 16:10

    The string class's Replace method can also be used to remove multiple characters from a string:

    Dim newstring As String
    newstring = oldstring.Replace(",", "").Replace(";", "")
    
    0 讨论(0)
  • 2021-02-18 16:23

    The String class has a Replace method that will do that.

    Dim clean as String
    clean = myString.Replace(",", "")
    
    0 讨论(0)
提交回复
热议问题