The code below is supposed to clean a string of all non-numeric characters, and then order them descending. However it seems to turn out the wrong result!
Current Output:
Original String: T5GJ2EyQYXuCX7hgEqMuW9Yg40Rmp8Y2dCjhc6dR Sanitized String: TGJEyQYXuCXhgEqMuWYgRmpYdCjhcdR -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,END
Can you figure out whats wrong? If you do, put the re-vamped line of code in the text box below and hit submit.
Good luck cheating on this one. The backend is completely unreadable! *evil laughter*
static void Main(string[] args) {
string ASetOfCharacters = GenerateString(40); //Generates string of random letters and numbers 40 characters long
Console.WriteLine("Original String: " + ASetOfCharacters);
//Remove Non-Numeric Characters
ASetOfCharacters = Regex.Replace(ASetOfCharacters, "[0-9]", "");
Console.WriteLine("Sanitized String: " + ASetOfCharacters);
//Now separate the numbers into individual items in an array
int[] IndividualNumbers = new int[ASetOfCharacters.Count()];
for(int i = 0; i < ASetOfCharacters.Count(); i++) {
IndividualNumbers[i] = (int)char.GetNumericValue(ASetOfCharacters[i]);
}
//Finally, sort the numbers by descending value
IndividualNumbers = IndividualNumbers.OrderByDescending(item => item).ToArray();
foreach(int a in IndividualNumbers) {
Console.Write(a + ",");
}
Console.WriteLine("END");
Console.ReadLine();
}