c# - How do i turn this into a for loop? -


hey im wondering how turn loop, don't have copy 26 times each letter of alphabet:

count[1] = str.split('a').length - 1; console.writeline("a comes x " + count[1]); 

count blank integer array takes 26 values, represent amount of times letter of alphabet in string str, stored in string array called letters

instead of splitting , creating new array, use count() function. can loop through each character, or loop existing array.

for (char c = 'a'; c <= 'z'; c++) {     console.writeline(c + " comes x " + str.count(x => char.toupper(x) == c)); } 

Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -