Replace the symbol "%" with the word "Percentage"

How to replace the symbol "%" with the word "Percentage".

My original line is: "Internal (%) External (%)". The string should be "Internal (percent) external (percent)"

Using regex, how can I replace this character?

Thanks in advance. Atul

+3
source share
4 answers

Here you do not need Regex, you can use the usual replacement. For example, using .net:

string s = "Internal (%) External (%)";
s = s.Replace("%", "Percent");
+10
source

the match string will be just a percent symbol:%

However, the implementation is specific to your regex environment.

Javascript

var myString = "Internal (%) External (%)";
myString = myString.replace(/%/g,"Percent");
+6
source

? , , Python...:

>>> "Internal (%) External (%)".replace('%','Percent')
'Internal (Percent) External (Percent)'

RE - , :

>>> import re
>>> re.sub('%', 'Percent', "Internal (%) External (%)")
'Internal (Percent) External (Percent)'

, RE , , , , ! -)

+5

Java %, .

myString = myString.replaceAll("%", "Percent");

, , % HTML

myString = myString.replaceAll("%", "%");
+3

Source: https://habr.com/ru/post/1744659/


All Articles