如何用字母和数字反转字符串,以便仅提取字母

问题描述 投票:0回答:1

如何反转包含数字和字母的字符串,但是我想以相反的顺序输出字母。 (不使用字符串函数)

string = 'Hellow 432'
length = len(string)
output = ""
while length>0:
   output += string[length-1]
   length = length-1
print (output)
string reverse
1个回答
0
投票
String details = "Hellow 432";
    string numeric = "";
    string nonnumeric = "";
    char[] mychar = details.ToCharArray();
    foreach (char ch in mychar)
    {
        if (char.IsDigit(ch))
        {

            numeric = numeric + ch.ToString();
        }
        else
        {
            nonnumeric =ch.ToString()+ nonnumeric;
        }
    }

 return nonnumeric + numeric;
}
© www.soinside.com 2019 - 2024. All rights reserved.