Sorting strings based on index of capital letter

Sandhyab
Posted by Sandhyab under C# category on | Points: 40 | Views : 1758
 string[] group = { "chenNai", "deLhi", "mUmbai", "Hyderabad", "kolKata", "punjaB", "rajastAn", "punewarRiors" };
int n = group.Length;
int[] indexOfCap = new int[n];
int count = 0;
string temp;
int inttemp;
for (int i = 0; i < n; i++)
{
for (int j = 0; j < group[i].Length; j++)
{
if ((group[i][j] >= 'A') && (group[i][j] <= 'Z'))
{
indexOfCap[count++] = j;


}

}
}


for (int k = 0; k < n; k++)
{
for (int l = 0; l < n - 1; l++)
{
if (indexOfCap[l] > indexOfCap[l + 1])
{
temp = group[l];
group[l] = group[l + 1];
group[l + 1] = temp;

inttemp = indexOfCap[l];
indexOfCap[l] = indexOfCap[l + 1];
indexOfCap[l + 1] = inttemp;
}
}
}


for (int h = 0; h < n; h++)
{
Response.Write(group[h] + "<br/>");
}

}

Comments or Responses

Login to post response