Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reverse any group of numbers in a string [closed]

Tags:

string

c#

reverse

I need reverse all group of digit in text for example

"test text 145 for 23 site 1"

we need this output

"test text 541 fro 32 site 1"
like image 936
jozi Avatar asked Feb 15 '23 05:02

jozi


1 Answers

C# Reverse all numbers in string?

Thanks to Yuriy Faktorovich

var replacedString = 
Regex.Replace(//finds all matches and replaces them
myString, //string we're working with
@"\d+", //the regular expression to match to do a replace
m => new string(m.Value.Reverse().ToArray())); //a Lambda expression which
    //is cast to the MatchEvaluator delegate, so once the match is found, it  
    //is replaced with the output of this method.
like image 92
htaghizadeh Avatar answered Feb 17 '23 06:02

htaghizadeh