i created my custom cyphers that are strings. when i try to run the code textbox1 is only returning vale of a single code its not appending , eg writing "4 5d" in textbox1 wont give a value but when i change the code from string textCiphered = myCipher.Cipher(textToBeCiphered); to string textCiphered = myCipher.Cipher("4", "5d"); its giving result " take 4 for 5 days"in texbox2. when i type 4 5d in textbox1 nothing is showing in textbox2, i need help in making the textbox1 work
My class code
class MyCipher : ICipherDecipher
{
private List<Code> alphabet;
public MyCipher()
{
alphabet = new List<Code>();
alphabet.Add(new Code("4", " take 4"));
alphabet.Add(new Code("3", " take 3"));
alphabet.Add(new Code("5d", " for 5 days"));
}
public string Cipher(params string[] codes)
{
StringBuilder result = new StringBuilder();
foreach (string code in codes)
{
Code element =
alphabet.Where(x => x.MyCode == code).SingleOrDefault();
if (element != null)
{
result.Append(element.MyDecoded);
}
}
return result.ToString();
}
class Code
{
public string MyCode;
public string MyDecoded;
public Code(string code, string decode)
{
MyCode = code;
MyDecoded = decode;
}
}
}
Button code where it needs editing
public partial class Form1 : Form
{
private ICipherDecipher myCipher;
public Form1()
{
myCipher = new MyCipher();
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
string textToBeCiphered = textBox1.Text;
string textCiphered = myCipher.Cipher(textToBeCiphered);
textBox2.Text = textCiphered;
}
}