C# Reverse all numbers in string?

前端 未结 2 2030
轮回少年
轮回少年 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:17

    Split the string on spaces. Then take the strings in the new string array that are digits and run this function on them:

    public static string Reverse( string s )
    {
       char[] charArray = s.ToCharArray();
       Array.Reverse( charArray );
       return new string( charArray );
    }
    

    Then recombine your array into a single string.

提交回复
热议问题