Invert any group of numbers into a string

I need the inverse of the entire group of numbers in the text, for example

"test text 145 for 23 site 1"

we need this conclusion

"test text 541 fro 32 site 1"
+4
source share
2 answers

C # Invert all numbers in a string?

Thanks to Yuri Factorovich

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.
+8
source

I will do something like this ... Although not tested

public string reverseString(string valuetoReverse)
{
    StringBuilder s = new StringBuilder();
    List<string> newString = valuetoReverse.Split(' ').Reverse().ToList();
    newString.ForEach(v => s.Append(v + String.Empty));
    return s.ToString();
}
0
source

All Articles