jsnaredude
jsnaredude

Reputation: 47

Replace integers in a string using Visual Basic

I am trying to replace integers in a string using Visual Basic and can't seem to get it just right.

This is what I currently have:

lblNewPassword.Text = txtOrigPassword.Text.Replace("[0-9]", "Z")

I have also tried:

lblNewPassword.Text = txtOrigPassword.Text.Replace("#", "Z")

And:

lblNewPassword.Text = txtOrigPassword.Text.Replace("*#*", "Z")

Upvotes: 0

Views: 1446

Answers (1)

Federico Piazza
Federico Piazza

Reputation: 30995

You have to use a regex object like this:

C#

string input = "This is t3xt with n4mb3rs.";
Regex rgx = new Regex("[0-9]");
string result = rgx.Replace(input, "Z");

VB

Dim input As String = "This is t3xt with n4mb3rs." 
Dim rgx As New Regex("[0-9]")
Dim result As String = rgx.Replace(input, "Z")

Update: if then you want to change vowels by X you can add:

rgx As New Regex("[A-Za-z]")
result = rgx.Replace(result, "X")

Upvotes: 3

Related Questions