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:
1 file changed
+40
-4
+40
-4
@@ -9,6 +9,7 @@
|
|||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
using System.Threading.Tasks.Dataflow;
|
using System.Threading.Tasks.Dataflow;
|
||||||
|
|
||||||
class PI114
|
class PI114
|
||||||
@@ -20,8 +21,8 @@ class PI114
|
|||||||
Console.WriteLine("└───────────────────────────────────────────────┘");
|
Console.WriteLine("└───────────────────────────────────────────────┘");
|
||||||
IDictionary<string, string> specialcharacterDictionnary = programeDictionnary();
|
IDictionary<string, string> specialcharacterDictionnary = programeDictionnary();
|
||||||
IDictionary<string, string> letterToMorse = programmeLetterToMorseCode();
|
IDictionary<string, string> letterToMorse = programmeLetterToMorseCode();
|
||||||
string userText = askUserSentence();
|
string[] userTextArray = askUserSentence();
|
||||||
string[] userTextArray = userTextToAnArray(userText);
|
verifyUserSentence(userTextArray, specialcharacterDictionnary);
|
||||||
translateUserSentenceToMorse(userTextArray, letterToMorse);
|
translateUserSentenceToMorse(userTextArray, letterToMorse);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -92,16 +93,51 @@ class PI114
|
|||||||
letterToMorse.Add(" ", "/");
|
letterToMorse.Add(" ", "/");
|
||||||
return letterToMorse;
|
return letterToMorse;
|
||||||
}
|
}
|
||||||
static string askUserSentence()
|
static string[] askUserSentence()
|
||||||
{
|
{
|
||||||
Console.Write("Entrez votre phrase à déchiffrer : ");
|
Console.Write("Entrez votre phrase à déchiffrer : ");
|
||||||
string userText = Console.ReadLine();
|
string userText = Console.ReadLine();
|
||||||
return userText;
|
string[] userTextArray = userTextToAnArray(userText);
|
||||||
|
return userTextArray;
|
||||||
}
|
}
|
||||||
|
|
||||||
static string[] userTextToAnArray(string userText)
|
static string[] userTextToAnArray(string userText)
|
||||||
{
|
{
|
||||||
string[] userTextArray = userText.Select(x => x.ToString()).ToArray();
|
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;
|
return userTextArray;
|
||||||
}
|
}
|
||||||
static void translateUserSentenceToMorse(string[] userTextArray, IDictionary<string, string> letterToMorse)
|
static void translateUserSentenceToMorse(string[] userTextArray, IDictionary<string, string> letterToMorse)
|
||||||
|
|||||||
Reference in new issue
Block a user