Click here to Skip to main content
15,918,168 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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

C#
string yourword = txtyourword.Text;

        try
        {
            Array.Sort(yourword);

            foreach (string str in yourword)
            {
                
            }

        }

        catch
        {
        }

please help me.
Posted
Updated 30-Jun-13 23:37pm
v2
Comments
sorawit amorn 4-Aug-13 14:10pm    
how do you mean by alphabetical order ? sorting all characters or you input multiple words

Try this:
C#
string str = txtyourword.Text;
char[] arr = str.ToCharArray();
Array.Sort(arr);
Response.Write(arr);

OR
C#
string str = txtyourword.Text;
char[] arr = str.OrderBy(s => s.ToString()).ToArray();
Console.WriteLine(arr);


And many more here[^].

--Amit
 
Share this answer
 
v2
Comments
Member 9567873 1-Jul-13 5:47am    
i have tried this code but it is not working for me.
_Amy 1-Jul-13 5:49am    
What is the input in TextBox? Can I see that?
ArunRajendra 1-Jul-13 5:51am    
Try this its same as Amit with a minor change

char[] temp = yourword.ToArray();
Array.Sort(temp);
string sorted = new string(temp);
Why on earth you wanted to do like this. Nevertheless

C#
char [] yourword = txtyourword.Text.ToArray();

            try
            {
                Array.Sort(yourword);

                foreach (var str in yourword)
                {
                   // Console.WriteLine(str);
                }
               // Console.ReadLine();
            }

            catch
            {
            }
 
Share this answer
 
v3
Comments
Member 9567873 1-Jul-13 5:56am    
thank you it worked
Sushil Mate 1-Jul-13 5:57am    
Happy to help.
Check following link. I hope it'll help you.

C# Sort

Sorting Arrays [C#]
 
Share this answer
 
Try this
C#
string s = "Mukesh";

        string[] myArray = new string[s.Length];
        for (int i = 0; i < s.Length; i++)
        {
            myArray[i] = s[i].ToString();
        }

        Array.Sort(myArray);
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900