Replace a list of invalid character with their valid version (like tr)

后端 未结 4 1107
你的背包
你的背包 2021-01-05 18:26

I need to do something like this dreamed .trReplace:

  str = str.trReplace(\"áéíüñ\",\"aeiu&\");

It should change this str

4条回答
  •  栀梦
    栀梦 (楼主)
    2021-01-05 19:19

    What you want is a way to go through the string once and do all the replacements. I am not not sure that regex is the best way to do it if you want efficiency. It could very well be that a case switch (for all the characters that you want to replace) in a for loop to test every character is faster. I would profile the two approaches.

提交回复
热议问题