diff --git a/Program.cs b/Program.cs index f892ca8..6822aca 100644 --- a/Program.cs +++ b/Program.cs @@ -8,6 +8,7 @@ class Program { static void Menu() { Console.Clear(); int scelta; + const int LUNGHEZZA = 100; string stringa1, stringa2; do { Console.WriteLine("Inserire un'opzione:"); @@ -28,7 +29,7 @@ class Program { Console.Clear(); stringa1 = Input(); stringa2 = Input(); - if (Controllo(stringa1, stringa2)) { + if (Controllo1(stringa1, stringa2)) { Console.WriteLine(AlternaCaratteri(stringa1, stringa2)); } else { @@ -43,7 +44,14 @@ class Program { break; case 3: Console.Clear(); - Console.WriteLine(PrimoCarattereMaiuscolo(Input())); + stringa1 = Input(); + + if (Controllo2(stringa1, LUNGHEZZA)) { + Console.WriteLine(PrimoCarattereMaiuscolo(stringa1)); + } + else { + Console.WriteLine($"Errore: la frase non può essere più lunga di {LUNGHEZZA} caratteri"); + } Pausa(); break; case 4: @@ -82,7 +90,7 @@ class Program { return Console.ReadLine(); } - static bool Controllo(string p_stringa1, string p_stringa2) { + static bool Controllo1(string p_stringa1, string p_stringa2) { bool ritorno; if (p_stringa1.Length == p_stringa2.Length) { ritorno = true; @@ -136,10 +144,26 @@ class Program { return string.Join("", ritorno).Split(inutile).First(); } - static string PrimoCarattereMaiuscolo(string p_stringa) { - string ritorno = char.ToUpper(p_stringa[0]) + p_stringa.Split(p_stringa[0]).Last(); - + static bool Controllo2(string p_stringa1, int p_lunghezza) { + bool ritorno; + if (p_stringa1.Length < p_lunghezza) { + ritorno = true; + } + else { + ritorno = false; + } return ritorno; + + } + + static string PrimoCarattereMaiuscolo(string p_stringa) { + string[] substrings = p_stringa.Split(); + + for (int i = 0; i < substrings.Length; i++) { + substrings[i] = char.ToUpper(substrings[i][0]) + substrings[i].Split(substrings[i][0]).Last().ToLower(); + } + + return string.Join(" ", substrings); } } diff --git a/bin/Debug/net9.0/strings_3.dll b/bin/Debug/net9.0/strings_3.dll index 53db1de..c26ffef 100644 Binary files a/bin/Debug/net9.0/strings_3.dll and b/bin/Debug/net9.0/strings_3.dll differ diff --git a/bin/Debug/net9.0/strings_3.pdb b/bin/Debug/net9.0/strings_3.pdb index 193fe6b..2152a9d 100644 Binary files a/bin/Debug/net9.0/strings_3.pdb and b/bin/Debug/net9.0/strings_3.pdb differ diff --git a/obj/Debug/net9.0/ref/strings_3.dll b/obj/Debug/net9.0/ref/strings_3.dll index e81b3a6..b9ab9a2 100644 Binary files a/obj/Debug/net9.0/ref/strings_3.dll and b/obj/Debug/net9.0/ref/strings_3.dll differ diff --git a/obj/Debug/net9.0/refint/strings_3.dll b/obj/Debug/net9.0/refint/strings_3.dll index e81b3a6..b9ab9a2 100644 Binary files a/obj/Debug/net9.0/refint/strings_3.dll and b/obj/Debug/net9.0/refint/strings_3.dll differ diff --git a/obj/Debug/net9.0/strings_3.AssemblyInfo.cs b/obj/Debug/net9.0/strings_3.AssemblyInfo.cs index f7e6d00..9b559bf 100644 --- a/obj/Debug/net9.0/strings_3.AssemblyInfo.cs +++ b/obj/Debug/net9.0/strings_3.AssemblyInfo.cs @@ -13,10 +13,10 @@ using System.Reflection; [assembly: System.Reflection.AssemblyCompanyAttribute("strings_3")] [assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")] [assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")] -[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+b2b1285d037b00410936752e5a623c5f2672c263")] +[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+9786e2adcd46bff810419c77a664ff038d4fb2bd")] [assembly: System.Reflection.AssemblyProductAttribute("strings_3")] [assembly: System.Reflection.AssemblyTitleAttribute("strings_3")] [assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")] -// Generated by the MSBuild WriteCodeFragment class. +// Generato dalla classe WriteCodeFragment di MSBuild. diff --git a/obj/Debug/net9.0/strings_3.AssemblyInfoInputs.cache b/obj/Debug/net9.0/strings_3.AssemblyInfoInputs.cache index 3b1d319..a0c2987 100644 --- a/obj/Debug/net9.0/strings_3.AssemblyInfoInputs.cache +++ b/obj/Debug/net9.0/strings_3.AssemblyInfoInputs.cache @@ -1 +1 @@ -ba2e54e8180aab2a82a9f8d460afffb6112678b22fc4465b8b01a6662a39f037 +62074303f49b761550171178f383c453b8b19d1e02f472014128ddf26529322b diff --git a/obj/Debug/net9.0/strings_3.dll b/obj/Debug/net9.0/strings_3.dll index 53db1de..c26ffef 100644 Binary files a/obj/Debug/net9.0/strings_3.dll and b/obj/Debug/net9.0/strings_3.dll differ diff --git a/obj/Debug/net9.0/strings_3.pdb b/obj/Debug/net9.0/strings_3.pdb index 193fe6b..2152a9d 100644 Binary files a/obj/Debug/net9.0/strings_3.pdb and b/obj/Debug/net9.0/strings_3.pdb differ