From 272f3e58aa0cd63ddca7f411951a96707e710f35 Mon Sep 17 00:00:00 2001 From: citizen-VM Date: Mon, 24 Aug 2020 21:29:23 +0200 Subject: [PATCH] feat: added support for commas and dots in the message * message check now passes when spaces, commas and dots are used in the message * closes #1 --- main_form.cs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/main_form.cs b/main_form.cs index c90fde9..f076e77 100644 --- a/main_form.cs +++ b/main_form.cs @@ -29,7 +29,16 @@ namespace KRY_0x01_ng public string restore_order(string str) { string alpha_str = Regex.Replace(str, "SPACEBRO", " "); - return alpha_str; + Regex.Replace(alpha_str, "COMMABRO", ","); + return Regex.Replace(alpha_str, "DOTBRO", "."); + } + + string introduce_chaos(string str) + { + string nustr = Regex.Replace(str, " ", "SPACEBRO"); + Regex.Replace(nustr, "W", "V"); + Regex.Replace(nustr, ",", "COMMABRO"); + return Regex.Replace(nustr, ".", "DOTBRO"); } public string pad(string str) @@ -155,14 +164,13 @@ namespace KRY_0x01_ng MessageBox.Show("Empty message, nothing to do.", "Warning"); return; } - string msg = Regex.Replace(tb_m.Text.ToUpper(), " ", "SPACEBRO"); + string msg = introduce_chaos(tb_m.Text.ToUpper()); Match match = Regex.Match(msg, @"\d|\s+"); if (match.Success) { - MessageBox.Show("Only alphabetic characters and spaces are allowed.\nCheck the message for numbers, symbols or tab whitespace and remove them before continuing.\nAlso, \"W\" will be replaced by \"V\".", "Error: invalid chars in message"); + MessageBox.Show("Only alphabetic characters, spaces, commas (,) and dots (.) are allowed.\nCheck the message for numbers, symbols or tab whitespace and remove them before continuing.\nAlso, \"W\" will be replaced by \"V\".", "Error: invalid chars in message"); return; } - msg = msg.Replace("W", "V"); textBox5.Text = msg; return; }