As mgebhard suggested you need to use ToLower to make your comparison case insensitive. however you will still get exception on second iteration onwards as after first replacement text in textbox
will be like A§ and this '§' value doesnt exist on dictionary as key. You might consider using the below Linq code to replace the characters from Dictionary
MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue.
If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.
None
0 Points
1 Post
Chaesar in C#
Dec 04, 2017 05:43 PM|CodeLikeAl3oSS|LINK
Hello,
I made something called Chaesar but I have a problem.
Dictionary<string, string> English = new Dictionary<string, string>();
English.Add("a", "§");
English.Add("b", "╚");
English.Add("c", "{");
English.Add("d", "A");
English.Add("e", "Ä");
English.Add("f", "█");
English.Add("g", "Õ");
English.Add("h", "T");
English.Add("i", "├");
English.Add("j", "e");
English.Add("k", "ƒ");
English.Add("l", "!");
English.Add("m", "á");
English.Add("n", "┤");
English.Add("o", "‗");
English.Add("p", "8");
English.Add("q", "Ì");
English.Add("r", "*");
English.Add("s", "&");
English.Add("t", "^");
English.Add("u", "%");
English.Add("v", "$");
English.Add("w", "#");
English.Add("x", "@");
English.Add("y", "(");
English.Add("z", "╣");
English.Add(" ", " ");
for (int i = 0; i < textBox1.TextLength; i++)
{
string MyChar = textBox1.Text[i].ToString();
textBox2.Text += English[MyChar];
}
}
everything works, but if I type in the textbox for example: "A" I get error, so my question is:
how can I make it with words like: "a", "A", "b", "b".
(sorry for my bad English)
and this is the first time I'm here, sorry if Im post in the wrong place
All-Star
53091 Points
23659 Posts
Re: Chaesar in C#
Dec 04, 2017 06:07 PM|mgebhard|LINK
string.ToLower();
All-Star
50841 Points
9895 Posts
Re: Chaesar in C#
Dec 04, 2017 07:58 PM|A2H|LINK
As mgebhard suggested you need to use ToLower to make your comparison case insensitive. however you will still get exception on second iteration onwards as after first replacement text in textbox will be like A§ and this '§' value doesnt exist on dictionary as key. You might consider using the below Linq code to replace the characters from Dictionary
make sure you add the below namespace to your page
Aje
My Blog | Dotnet Funda
Star
8670 Points
2882 Posts
Re: Chaesar in C#
Dec 05, 2017 08:59 AM|Cathy Zou|LINK
Hi CodeLikeAl3oSS,
Working sample as below:
CodeBehind:
Output:
Best regards
Cathy
Please remember to click "Mark as Answer" the responses that resolved your issue.
If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.