1
Answer

Sorting an Array of strings - minor issue.

Arfan Dhillon

Arfan Dhillon

15y
2.9k
1

Hi guys.
The code below reads in a string, splits the string into an array with every comma. Then alphabetically sorts the array and re-joins the string with a comma in between (and also removes that last comma afterwards).
 
 

static string alphabeticallyOrderString(string lineholderX)
{
string tmpLength = "";

string[] stringSplit = Regex.Split(lineholderX, ",");
Array.Sort(stringSplit);

lineholderX =
"";
for (int i = 0; i < stringSplit.Length; i++)
{
if (stringSplit[i] != "")
{
tmpLength =
"";
lineholderX += tmpLength + stringSplit[i] +
",";
}
}
char lastComma = ',';
lineholderX = lineholderX.TrimEnd(lastComma);
return lineholderX;
}

If my input string is " UE-CA , UF-BA , UF-AB , OF-AB ," , I want my output string to be " UE-CA , UF-AB , OF-AB , UF-BA". However my code below will output it as " OF-AB , UE-CA , UF-AB , UF-BA". The problem occurs with OF-AB f.
I would like to sort the array by ignoring the first letter of the each string, but still output the same result above.
I appreciate any help and thank you in advance. Also, I know my coding method might be questionable, but it sort of works.
Answers (1)
0
Armin Dashti

Armin Dashti

NA 45 953 7y
Is there anybody to help me?
0
Armin Dashti

Armin Dashti

NA 45 953 7y
Thanks. but i don't get anything with this link.
I cheked this code and nothing .
What i do?
0
Gokhul Varman

Gokhul Varman

NA 10.7k 9.4k 7y
Please refer the link for more detailed explanation:https://stackoverflow.com/questions/17026204/retrieve-process-network-usage