Function to Sort comma(,) separated string

You can sort the comma separated values in the string by using below function.

public string SortCommaSeparatedString(string name)
string[] stringArray = name.Split(',');
string returnValue = "";
for (int i = stringArray.GetLowerBound(0); i <= stringArray.GetUpperBound(0); i++)
returnValue = returnValue + stringArray[i] + ",";
return returnValue.Remove(returnValue.Length-1,1);

You can call above function as shown below:

string name="Amit,Piyush,Anushka,Priya,Shreya,Ipun";


  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name: