开发者

Replacing plus sign "+" in vb.net

开发者 https://www.devze.com 2023-02-22 19:20 出处:网络
I am trimming some strings but I am unable to do anything about the strings containing plus signs. For example if I have this str开发者_开发百科ing with a telephone number

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

For example if I have this str开发者_开发百科ing 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?


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'


Try...

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

0

精彩评论

暂无评论...
验证码 换一张
取 消