diff --git a/Program.cs b/Program.cs index 2673b5a..15016b7 100644 --- a/Program.cs +++ b/Program.cs @@ -74,22 +74,29 @@ class Program { static void ContaLettere() { string daEsserCercato, stringa; - int vocali, consonanti; + int numeroVocali = 0, numeroConsonanti = 0; + char[] vocali = { 'a', 'e', 'i', 'o', 'u' }, consonanti = { 'b', 'c', 'd', 'f', 'g', 'h', 'j', 'k', 'l', 'm', 'n', 'p', 'q', 'r', 's', 't', 'v', 'w', 'x', 'y', 'z' }; Console.Write("Inserire il testo in cui contare le lettere: "); daEsserCercato = Console.ReadLine(); - stringa = daEsserCercato.ToLower();//converto la stringa in caratteri minuscoli per semplificare la ricerca delle lettere dopo + //converto la stringa in caratteri minuscoli per semplificare la ricerca delle lettere dopo //Queste sono due addizioni lunghissime perché ho voluto cercare di usare solo i metodi delle stringhe e non convertire la stringa in array per la ricerca - vocali = CercaLettera(stringa, 'a') + CercaLettera(stringa, 'e') + CercaLettera(stringa, 'i') + CercaLettera(stringa, 'o') + CercaLettera(stringa, 'u'); - consonanti = CercaLettera(stringa, 'b') + CercaLettera(stringa, 'c') + CercaLettera(stringa, 'd') + CercaLettera(stringa, 'f') + CercaLettera(stringa, 'g') + CercaLettera(stringa, 'h') + CercaLettera(stringa, 'j') + CercaLettera(stringa, 'k') + CercaLettera(stringa, 'l') + CercaLettera(stringa, 'm') + CercaLettera(stringa, 'n') + CercaLettera(stringa, 'p') + CercaLettera(stringa, 'q') + CercaLettera(stringa, 'r') + CercaLettera(stringa, 's') + CercaLettera(stringa, 't') + CercaLettera(stringa, 'v') + CercaLettera(stringa, 'w') + CercaLettera(stringa, 'x') + CercaLettera(stringa, 'y') + CercaLettera(stringa, 'z'); + for (int i = 0; i < vocali.Length; i++) { + numeroVocali = numeroVocali + CercaLettera(daEsserCercato.ToLower(), vocali[i]); + } - Console.WriteLine($"La stringa {daEsserCercato} contiene {vocali} vocali e {consonanti} consonanti"); + for (int i = 0; i < consonanti.Length; i++) { + numeroConsonanti = numeroConsonanti + CercaLettera(daEsserCercato.ToLower(), consonanti[i]); + } + + Console.WriteLine($"La stringa {daEsserCercato} contiene {numeroVocali} vocali e {numeroConsonanti} consonanti"); } static int CercaLettera(string p_stringa, char p_lettera) { int i = 0, ritorno = 0; + //creo un array per avere l'indice iniziale di ogni occorrenza del testo da trovare e lo riempio di -1 visto che sono indici non validi int[] indiciOccorrenze = new int[p_stringa.Length]; for (int j = 0; j < indiciOccorrenze.Length; j++) { @@ -196,4 +203,4 @@ class Program { Console.WriteLine($"La frase con le lettere scambiate è: {stringa3}{stringa2}{stringa1}"); } -} +} \ No newline at end of file diff --git a/bin/Debug/net9.0/strings_1.dll b/bin/Debug/net9.0/strings_1.dll index 59e027a..6dc326a 100644 Binary files a/bin/Debug/net9.0/strings_1.dll and b/bin/Debug/net9.0/strings_1.dll differ diff --git a/bin/Debug/net9.0/strings_1.pdb b/bin/Debug/net9.0/strings_1.pdb index 6f00e0b..dc27abf 100644 Binary files a/bin/Debug/net9.0/strings_1.pdb and b/bin/Debug/net9.0/strings_1.pdb differ diff --git a/obj/Debug/net9.0/ref/strings_1.dll b/obj/Debug/net9.0/ref/strings_1.dll index 70e8ae3..c6a154f 100644 Binary files a/obj/Debug/net9.0/ref/strings_1.dll and b/obj/Debug/net9.0/ref/strings_1.dll differ diff --git a/obj/Debug/net9.0/refint/strings_1.dll b/obj/Debug/net9.0/refint/strings_1.dll index 70e8ae3..c6a154f 100644 Binary files a/obj/Debug/net9.0/refint/strings_1.dll and b/obj/Debug/net9.0/refint/strings_1.dll differ diff --git a/obj/Debug/net9.0/strings_1.AssemblyInfo.cs b/obj/Debug/net9.0/strings_1.AssemblyInfo.cs index b0df734..07286f2 100644 --- a/obj/Debug/net9.0/strings_1.AssemblyInfo.cs +++ b/obj/Debug/net9.0/strings_1.AssemblyInfo.cs @@ -13,7 +13,7 @@ using System.Reflection; [assembly: System.Reflection.AssemblyCompanyAttribute("strings_1")] [assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")] [assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")] -[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+ccf2dfdddbb4c94a19e023f37e05913e2545cff7")] +[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+ef6982364c3b85f5abbd9e552f049ee23a4b1a38")] [assembly: System.Reflection.AssemblyProductAttribute("strings_1")] [assembly: System.Reflection.AssemblyTitleAttribute("strings_1")] [assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")] diff --git a/obj/Debug/net9.0/strings_1.AssemblyInfoInputs.cache b/obj/Debug/net9.0/strings_1.AssemblyInfoInputs.cache index e14dedc..ef00a4e 100644 --- a/obj/Debug/net9.0/strings_1.AssemblyInfoInputs.cache +++ b/obj/Debug/net9.0/strings_1.AssemblyInfoInputs.cache @@ -1 +1 @@ -d4a8bf2719c6ab479c0f2d6052891a9062b0f984718d04ce460f7e151ca9bbeb +bc266582043c6cbe365895284df0356337a847a5502031505a658f679d75e496 diff --git a/obj/Debug/net9.0/strings_1.dll b/obj/Debug/net9.0/strings_1.dll index 59e027a..6dc326a 100644 Binary files a/obj/Debug/net9.0/strings_1.dll and b/obj/Debug/net9.0/strings_1.dll differ diff --git a/obj/Debug/net9.0/strings_1.pdb b/obj/Debug/net9.0/strings_1.pdb index 6f00e0b..dc27abf 100644 Binary files a/obj/Debug/net9.0/strings_1.pdb and b/obj/Debug/net9.0/strings_1.pdb differ