C# Reverse all numbers in string?

前端 未结 2 2028
轮回少年
轮回少年 2021-02-10 00:47

I have a string:

\"Hello 7866592 this is my 12432 string and 823 i need to flip all 123\"

2条回答
  •  醉梦人生
    2021-02-10 01:20

    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.
    

提交回复
热议问题