Charkel
Charkel

Reputation: 338

Replacing plus sign "+" in vb.net

I am trimming some strings but I am unable to do anything about the strings containing plus signs.

For example if I have this string with a telephone number

Dim str As String = "+46765124246"

And try

str.replace("+46", "0")

Nothing changes in the string.

Why is this and how do I do it?

Upvotes: 0

Views: 1029

Answers (2)

Zarigani
Zarigani

Reputation: 835

Try...

str = str.replace("+46", "0")

Upvotes: 0

NerdFury
NerdFury

Reputation: 19214

The replace function, and most sting functions are non-destructive. The original string is left alone. In order to work with the result, you need to assign the result back to a variable.

str = str.Replace("+46", "0")

or

Dim result as String
result = str.Replace("+46", "0")
Console.WriteLine(result) ' Prints '0765124246' str still equals '+42765124246'

Upvotes: 2

Related Questions