Replacing character in string

jdy0803

Well-known member
Joined
Sep 9, 2012
Messages
73
Location
Santa Clarita
Programming Experience
10+
I'm converting VB 6.0 program to VB.NET.
In case of VB6 code, Mid$(strTmp, i, 1),
I can convert it like following.

strTmp.SubString(i-1, 1)

But when I try replace that character, error occurs from following code

strTmp.SubString(i-1, 1) = "0"
How to replace character in the string?
Can somebody give me any advice?
 
There are two types of Mid statement in VB6: the one that gets data from a String and the one that sets data in a String. In .NET, String.Substring is equivalent to the latter but there is no equivalent to the former. You can still just use that Mid statement in VB.NET if you want but if you want to avoid that then you'll need to call Substring twice, to get the substrings on either side of the part that you want to replace, and then concatenate them back together with the new part in between.
 
If it's a unique character , you can also use string.replace()

Sent using XT910 with Android 4.0.4 and MIUI 2.8.10
 
If it's a unique character , you can also use string.replace()
If you do do that then be aware that, like all String manipulating functions in .NET, it doesn't actually affect the current instance but rather creates a new instance containing the modification.
 
Can vb.net replace function help you?
E.g. txtsample.text = Replace(txtsample.text,"\","/")
 
Back
Top