Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET C#4.0
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.
Posted 1-Jul-13 0:35am
Edited 1-Jul-13 0:37am
v2
Comments
sorawit amorn at 4-Aug-13 14:10pm
   
how do you mean by alphabetical order ? sorting all characters or you input multiple words
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Try this:
string str = txtyourword.Text;
char[] arr = str.ToCharArray();
Array.Sort(arr);
Response.Write(arr);
OR
string str = txtyourword.Text;
char[] arr = str.OrderBy(s => s.ToString()).ToArray();
Console.WriteLine(arr);
 
And many more here[^].
 
--Amit
  Permalink  
v2
Comments
Member 9567873 at 1-Jul-13 5:47am
   
i have tried this code but it is not working for me.
_Amy at 1-Jul-13 5:49am
   
What is the input in TextBox? Can I see that?
ArunRajendra at 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);
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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
            {
            }
  Permalink  
v3
Comments
Member 9567873 at 1-Jul-13 5:56am
   
thank you it worked
Sushil Mate at 1-Jul-13 5:57am
   
Happy to help.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

Check following link. I hope it'll help you.

C# Sort
 
Sorting Arrays [C#]
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

Try this
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);
  Permalink  

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

  Print Answers RSS
0 George Jonsson 175
1 Kornfeld Eliyahu Peter 169
2 Zoltán Zörgő 139
3 PIEBALDconsult 130
4 OriginalGriff 120
0 OriginalGriff 6,165
1 DamithSL 4,658
2 Maciej Los 4,107
3 Kornfeld Eliyahu Peter 3,649
4 Sergey Alexandrovich Kryukov 3,342


Advertise | Privacy | Mobile
Web02 | 2.8.141220.1 | Last Updated 1 Jul 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100