Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Converting VB.net replace to C#

Tags:

c#

asp.net

vb.net

I want convert this VB.net snippet to C#

sURL = Replace(sURL,"%F9","%C3%B9",,,CompareMethod.Text)

Which one of these is better?

sURL = Strings.Replace(sURL,"%F3","%C3%B3", 1, -1, CompareMethod.Text);
sURL = Regex.Replace(sURL,"%FA","%C3%BA",CompareMethod.Text);
like image 384
Cornwell Avatar asked Feb 21 '26 23:02

Cornwell


2 Answers

Regex replace is used for Regular expressions. Here you haven't regular expression, so it's better to use usual replace:

sURL = sURL.Replace("%F3","%C3%B3");
like image 153
Sergey Litvinov Avatar answered Feb 24 '26 13:02

Sergey Litvinov


I simple String.Replace will be more efficient than Regex.Replace when you are doing a straightforward text-replace. If you don't need any of the features of Regex, it's best not to use it.

like image 28
Steven Doggart Avatar answered Feb 24 '26 11:02

Steven Doggart



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!