From 27747a3b96064392028ee4524c9e549647ee81d2 Mon Sep 17 00:00:00 2001 From: fkDeath Date: Mon, 7 Sep 2026 10:36:14 +0200 Subject: [PATCH] feat: add character verification and refactor user input handling - Add System.Runtime.InteropServices using statement - Refactor askUserSentence() to return string[] instead of string - Move userTextToAnArray() conversion into askUserSentence() - Add new verifyUserSentence() method to validate and replace special characters - Add console output in userTextToAnArray() to display array conversion - Simplify main() flow by removing intermediate variable assignment --- Program.cs | 44 ++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 40 insertions(+), 4 deletions(-) diff --git a/Program.cs b/Program.cs index caa7c09..4bc89b1 100644 --- a/Program.cs +++ b/Program.cs @@ -9,6 +9,7 @@ using System; using System.Linq; +using System.Runtime.InteropServices; using System.Threading.Tasks.Dataflow; class PI114 @@ -20,8 +21,8 @@ class PI114 Console.WriteLine("└───────────────────────────────────────────────┘"); IDictionary specialcharacterDictionnary = programeDictionnary(); IDictionary letterToMorse = programmeLetterToMorseCode(); - string userText = askUserSentence(); - string[] userTextArray = userTextToAnArray(userText); + string[] userTextArray = askUserSentence(); + verifyUserSentence(userTextArray, specialcharacterDictionnary); translateUserSentenceToMorse(userTextArray, letterToMorse); } @@ -92,16 +93,51 @@ class PI114 letterToMorse.Add(" ", "/"); return letterToMorse; } - static string askUserSentence() + static string[] askUserSentence() { Console.Write("Entrez votre phrase à déchiffrer : "); string userText = Console.ReadLine(); - return userText; + string[] userTextArray = userTextToAnArray(userText); + return userTextArray; } static string[] userTextToAnArray(string userText) { string[] userTextArray = userText.Select(x => x.ToString()).ToArray(); + Console.WriteLine(string.Join("", userTextArray)); + return userTextArray; + } + static string[] verifyUserSentence(string[] userTextArray, IDictionary specialcharacterDictionnary) + { + int i = 0; + foreach( KeyValuePair v in specialcharacterDictionnary) + { + foreach( string k in userTextArray ) + { + if (v.Key.Equals(k)) + { + userTextArray[i] = v.Value; + Console.WriteLine("Character : {0} Modifié en {1}", k, userTextArray[i]); + } + // else if () + // { + + // } à faire character accepté + + // else if (!v.Key.Contains(k)) + // { + // while (!v.Key.Contains(k)) + // { + // Console.WriteLine("Veuillez entrer votre phrase sans charactère spéciale"); + // string newText = Console.ReadLine(); + // userTextArray = userTextToAnArray(newText); + // } + // continue; + // } à mettre en else + + } + i++; + } return userTextArray; } static void translateUserSentenceToMorse(string[] userTextArray, IDictionary letterToMorse)