开发者

Percentage position move

Is there a simple way to move percentage pointer after the value:

120 @ %60 {a} >> 120 @开发者_开发技巧 60% {a}


Try this:

string input = "120 @ %60 {a}";
string pattern = @"%(\d+)";
string result = Regex.Replace(input, pattern, "$1%");
Console.WriteLine(result);

The %(\d+) pattern matches a % symbol followed by at least one digit. The digits are captured in a group which is referenced via the $1 in the replacement pattern $1%, which ends up placing the % symbol after the captured number.

If you need to account for numbers with decimal places, such as %60.50, you can use this pattern instead: @"%(\d+(?:\.\d+)?)"

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜