Is there a simple way that I can sort characters in a string in alphabetical order
Solution 1:
You can use LINQ:
String.Concat(str.OrderBy(c => c))
If you want to remove duplicates, add .Distinct()
.
Solution 2:
Yes; copy the string to a char array, sort the char array, then copy that back into a string.
static string SortString(string input)
{
char[] characters = input.ToArray();
Array.Sort(characters);
return new string(characters);
}
Solution 3:
new string (str.OrderBy(c => c).ToArray())