Simonetos Simonetos - 2 years ago 141 Question

VB.NET - Find and replace a range of text from a text box

Into a Visual Basic project I am trying to replace a part of URL coming from a text box. For example, I have this
URL into
and I want to replace the part

I did it by doing something like this:
Dim url = Replace(TextBox1.Text, "/s912-", "/s1600-")
. But, this URL isn't the same every time. The part
coould be
for example. So my next though is to use an asterik:
Dim url = Replace(TextBox1.Text, "/s*-", "/s1600-")
. Of course it doesn'r work! So I need help with the syntax or a better idea.

Answer Source

Regex.Replace can be used to search/replace using a regular expression.

Dim input = ""
Dim output = Regex.Replace(input, "/s\d+-", "/s1600-")

output is:

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download