When to use Regex vs Built in String Methods?

后端 未结 6 716
庸人自扰
庸人自扰 2021-01-12 07:03

I\'ve noticed a lot of little debates about when to use regex and when to use a built in string function like String.Replace() (.NET).

It seems a lot of people recom

6条回答
  •  醉酒成梦
    2021-01-12 07:41

    Regex.Replace() is much more expensive than the String.Replace() method. Use String.Replace() when possible, and use Regex when it's a necessity.

    Take a look at this benchmark to see the time differences.

提交回复
热议问题