0

A little help with strings in c#

i can only print the numbers of characters and i was wondering how can i print words that start with a specific letter ? i want to print the words hi and how. string str = "hi how are you?"; int count = 0; foreach(char letter in str) { if (letter == 'h') { count++; } } Console.WriteLine("the number of characters of h is:{0}", count); Console.ReadLine();

17th Jun 2020, 4:51 AM
vinicio a Vargas
vinicio a Vargas - avatar
1 Odpowiedź
+ 5
split with space, loop over the array, if the first character is h, print the item
17th Jun 2020, 5:15 AM
Gordon
Gordon - avatar