如何回收字符串中的单词并按字母顺序排列单词 [英] How to revesre a words in the string and arrange the words in alphabetical order
问题描述
i想要知道如何反转字符串中的单词。之后我想知道我在一个集合顺序中反向的单词。
我尝试了什么:
实际上我尝试过预定义的方法,但是我不想那样。请不要使用预定义的方法来帮助它。
const string s1 =比尔盖茨是地球上最富有的人;
const string s2 =Srinivasa Ramanujan是一位才华横溢的数学家;
string rev1 = Program.ReverseWords(s1);
Console.WriteLine(rev1);
string rev2 = Program.ReverseWords(s2);
Console.WriteLine(rev2);
Console.ReadLine();
Hi ,
i want know the how to reverse the words in a string.After that i want know the i arrage the reverse words in a assending order.
What I have tried:
Actually i tried with predefind methods,but i dont want that.please help this without using predefined methods.
const string s1 = "Bill Gates is the richest man on Earth";
const string s2 = "Srinivasa Ramanujan was a brilliant mathematician";
string rev1 = Program.ReverseWords(s1);
Console.WriteLine(rev1);
string rev2 = Program.ReverseWords(s2);
Console.WriteLine(rev2);
Console.ReadLine();
推荐答案
public static string ReverseString(string s)
{
char[] arr = s.ToCharArray();
Array.Reverse(arr);
return new string(arr);
}
这篇关于如何回收字符串中的单词并按字母顺序排列单词的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!