Hi,Am creating program to translate morse code to text and text to morse code. First it worked fine with basic characeters in dictionary: abcdefghijklmnoprstuvzy0123456789 .Than i want to upgrade it to translate special characters in my language like áéäňöü .Problem is when i write it to my dictionary and give every char key it throws me excpetion : System.ArgumentException: An item with the same key has already been added, even if it is only once in dictionary. Every key value is unique.
This is my reading dictionary code
private void ReadDictionary(string filename)
{
string cesta = Path.GetDirectoryName(Process.GetCurrentProcess().MainModule.FileName);
try {
string[] lines = File.ReadAllLines(filename,Encoding.UTF8);
if (lines != null) {
}
foreach (string line in lines)
{
string[] znaky = line.Split('=');
string key = znaky[0];
string value = znaky[1];
this.morzeovka.Add(key, value);
this.latinka.Add(value, key);
}
}
catch (IOException) {
MessageBox.Show("Nepodarilo sa nacitat slovnik"+ Environment.NewLine + "Skontrolujete umiestnenie slovníka v: "+cesta,"Chyba",MessageBoxButtons.OK,MessageBoxIcon.Error);
System.Environment.Exit(1);
}
}
}
This is my dictionary
a=.-
b=-...
c=-.-.
d=-..
e=.
f=..-.
g=--.
h=....
i=..
j=.---
k=-.-
l=.-..
m=--
n=-.
o=---
p=.--.
q=--.-
r=.-.
s=...
t=-
u=..-
v=...-
w=.--
x=-..-
y=-.--
z=--..
1=.----
2=..---
3=...--
4=....-
5=.....
6=-....
7=--...
8=---..
9=----.
0=-----
.=.-.-.-
,=--..--
?=..--..
!=--..-
;=-.-.-.
:=---...
(=--...
)=-.--.-
"=.-..-.
-=-....-
_=..--.-
@=.--.-.
+=.-.-.
/=-..-.
'=.----.
á=.--.-
ä=.-.-
é=..-..
ö=---.
ü=..--
ň=--.--
This is the full exception
System.ArgumentException: An item with the same key has already been added.
at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource)
at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
at System.Collections.Generic.Dictionary`2.Add(TKey key, TValue value)
Thanks for any help
PS: When i strat debugging and put breakpoint to line this.latinka.Add(value, key); it throws me exception. So problematic keys-values are
á=.--.-
ä=.-.-
é=..-..
ö=---.
ü=..--
ň=--.--