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
This commit is contained in:
nocode committed 2026-09-07 10:36:14 +02:00
1 parent 07afbb1486
commit 27747a3b96
1 file changed
+40 -4
+40 -4
View File
@@ -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<string, string> specialcharacterDictionnary = programeDictionnary();
IDictionary<string, string> 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<string, string> specialcharacterDictionnary)
{
int i = 0;
foreach( KeyValuePair<string, string> 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<string, string> letterToMorse)