On 12.01.2012 13:06, Shapper wrote:
> I need to convert strings as "4.32%" or "4,32%" to "4 32 percent". So I am using:
>
> Regex.Replace(value, @"\s*%\s*", " percent ").
> This fails because "4.32%" or "4,32%" does not become "4 32 percent" but "4.32 percent".
Of course, you only replaced the % sign and the surrounding white space
characters.
> I would like to have this done only with Regex.
Regex.Replace(value, @"\s*(\d+)[,.](\d\d)\s*%\s*", "$1 $2 percent")
If the replacement fails, your input string has not the expected syntax.
Marcel