按字母顺序排序字符串 [英] sorting a string in alphabetical order
本文介绍了按字母顺序排序字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
下午好,
i有两个文本框。
如果我在第一个文本框中输入字符串按一个按钮,该字符串应按字母顺序排序,并应显示在第二个文本框中。
i我正在使用
good afternoon,
i have two textboxes.
if i give string in first textbox and press a button, that string should be sorted in alphabetical order and should be displayed in second textbox.
i am using
string yourword = txtyourword.Text;
try
{
Array.Sort(yourword);
foreach (string str in yourword)
{
}
}
catch
{
}
请帮帮我。
please help me.
推荐答案
试试这个:
Try this:
string str = txtyourword.Text;
char[] arr = str.ToCharArray();
Array.Sort(arr);
Response.Write(arr);
OR
OR
string str = txtyourword.Text;
char[] arr = str.OrderBy(s => s.ToString()).ToArray();
Console.WriteLine(arr);
为什么你想这样做。然而
Why on earth you wanted to do like this. Nevertheless
char [] yourword = txtyourword.Text.ToArray();
try
{
Array.Sort(yourword);
foreach (var str in yourword)
{
// Console.WriteLine(str);
}
// Console.ReadLine();
}
catch
{
}
检查以下链接。我希望它能帮到你。
C#Sort
排序数组[C#]
Check following link. I hope it'll help you.
C# Sort
Sorting Arrays [C#]
这篇关于按字母顺序排序字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文