Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VB.NET - Remove a characters from a String

Tags:

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!

like image 928
Jonathan Rioux Avatar asked Mar 22 '11 21:03

Jonathan Rioux


People also ask

How do you remove a specific character from a string in VB?

You can also remove a specified character or substring from a string by calling the String. Replace(String, String) method and specifying an empty string (String. Empty) as the replacement. The following example removes all commas from a string.

How do you remove characters from a string?

Using 'str. replace() , we can replace a specific character. If we want to remove that specific character, replace that character with an empty string. The str. replace() method will replace all occurrences of the specific character mentioned.

How can I remove last 3 characters from a string in VB net?

Try your Remove call with Length - 2 . To remove all the whitespace characters (newlines, tabs, spaces, ...) just call TrimEnd without passing anything.

What is remove in VB net?

Remove(Int32, Int32) Returns a new string in which a specified number of characters in the current instance beginning at a specified position have been deleted.


2 Answers

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

Dim clean as String clean = myString.Replace(",", "") 
like image 124
Oded Avatar answered Oct 24 '22 02:10

Oded


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

like image 21
rlb.usa Avatar answered Oct 24 '22 03:10

rlb.usa