• I'm attempting to create a code in C# that will "compress" a string. It should print how many of each ASCII character is in a inputted word?

    If the user inputs the word "HELLO", then the code should write "H1 E1 L2 O1". However, if it was "HELLOL", the code should write "H1 E1 L2 O1 L1". So it should only do the numbers higher than one with consecutive letters. This is the code i have written so far. I need some improvements on it so that it will... show more
    If the user inputs the word "HELLO", then the code should write "H1 E1 L2 O1". However, if it was "HELLOL", the code should write "H1 E1 L2 O1 L1". So it should only do the numbers higher than one with consecutive letters. This is the code i have written so far. I need some improvements on it so that it will function properly. Console.WriteLine("Please enter a word."); string a = Console.ReadLine(); int b = a.Length; int c = 0; while (c < b) { string d = a.Substring(c, 1); Console.WriteLine(d); c++; string e = a.Substring(c, 1); while (d == e) { int f = 2; Console.Write(f); int g = c + 1; d = a.Substring(g, 1); } } Console.ReadLine();
    2 answers · Programming & Design · 1 month ago