How to return the characters in the string in alphabetical order

Saratvaddilli
Posted by Saratvaddilli under C# category on | Points: 40 | Views : 1776
In Aspx Page
 <asp:Label ID="lblMeassage" runat="server" />
<asp:TextBox ID="TB1" runat="server" />
<asp:Button ID="bt1" runat="server" OnClick="getString" />


In Code behind
  protected void getString(object sender, EventArgs e)
{

string Input = TB1.Text.Trim();
Input = Input.Replace(" ", "");
char[] In = Input.ToCharArray();
Array.Sort<char>(In);
StringBuilder OutPut = new StringBuilder();
char Ou = In[0];

for (int i = 0; i < In.Length; i++)
{
if (In[i] != Ou )
{
OutPut.Append(" ");
Ou = In[i + 1];
}
}
OutPut.Append(In);
lblMeassage.Text = OutPut.ToString();
}

Comments or Responses

Login to post response