Opzione 4
This commit is contained in:
parent
6415a06c85
commit
7775755438
33
Program.cs
33
Program.cs
@ -56,7 +56,18 @@ class Program {
|
||||
break;
|
||||
case 4:
|
||||
Console.Clear();
|
||||
//Input4();
|
||||
Console.WriteLine("È richiesta la frase in cui effettuare la ricerca");
|
||||
stringa1 = Input();
|
||||
Console.WriteLine();
|
||||
Console.WriteLine("È richiesta la frase che verrà sostituita");
|
||||
stringa2 = Input();
|
||||
Console.WriteLine();
|
||||
if (Controllo2(stringa2, stringa1.Length)) {
|
||||
Console.WriteLine(TrovaESostituisci(stringa1, stringa2));
|
||||
}
|
||||
else {
|
||||
Console.WriteLine($"Errore: la frase da cercare non può essere più lunga della frase in cui cercare");
|
||||
}
|
||||
Pausa();
|
||||
break;
|
||||
case 5:
|
||||
@ -166,4 +177,24 @@ class Program {
|
||||
|
||||
return string.Join(" ", substrings);
|
||||
}
|
||||
|
||||
static string TrovaESostituisci(string p_stringa1, string p_stringa2) {
|
||||
string ritorno;
|
||||
const string sostituisci = "*";
|
||||
|
||||
if (p_stringa1.Contains(p_stringa2)) {
|
||||
ritorno = p_stringa1;
|
||||
for (int i = 0; i < p_stringa2.Length; i++) {
|
||||
ritorno = ritorno.Replace(p_stringa2[i], Convert.ToChar(sostituisci));
|
||||
}
|
||||
|
||||
}
|
||||
else {
|
||||
ritorno = $"Nessuna occorrenza di {p_stringa2} trovata in {p_stringa1}";
|
||||
}
|
||||
|
||||
return ritorno;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -13,7 +13,7 @@ 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+9786e2adcd46bff810419c77a664ff038d4fb2bd")]
|
||||
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+6415a06c85cfa74b112fb81faf09820fc9a42aaf")]
|
||||
[assembly: System.Reflection.AssemblyProductAttribute("strings_3")]
|
||||
[assembly: System.Reflection.AssemblyTitleAttribute("strings_3")]
|
||||
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
|
||||
|
||||
@ -1 +1 @@
|
||||
62074303f49b761550171178f383c453b8b19d1e02f472014128ddf26529322b
|
||||
daf4d26f162aad74b0d6ca9d5e46d1f534c7df8294bd270db72667436b646006
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user