I am new to programming. These is my code:
public string ThanglishToTamilList(char[] characters, int length) {
var dict1 = new Dictionary<string, string>();
dict1.Add("a", "\u0B85"); // அ
dict1.Add("aa", "\u0B86"); // ஆ
dict1.Add("A", "\u0B86"); // ஆ
dict1.Add("i", "\u0B87"); // இ
dict1.Add("ee", "\u0B88"); // ஈ
dict1.Add("I", "\u0B88"); // ஈ
dict1.Add("u", "\u0B89"); // உ
...
List<String> list = new List<String>();
string[] array;
var valueOfDictOne = "";
for (int i = 0; i < length; i++)
{
try
{
valueOfDictOne = dict1[characters[i].ToString()];
list.Add(valueOfDictOne);
}
catch
{
list.Add(characters[i].ToString());
}
}
array = list.ToArray();
string result = string.Join("", array);
return result;
}
function Parameter details:
char[] characters : Array of characters (textbox.text.ToCharArray())
int length : length of the array. (no of characters we typed in the text box)
My expected output should be:
If the user types a -> Output should be அ.
Likewise:
a -> அ
aa -> ஆ
A -> ஆ ...
note that aa & A represent same ஆ
My Problem: This code only replace one charecter (a -> அ), This works fine.
But if we type aa the output is அஅ
aa -> அஅ
But I need the correct output as
aa -> ஆ
I have added some lines of codes for this. but this did not work:
...
for (int i = 0; i < length; i++)
{
try
{
if (String.Equals(characters[i], "a") && !(String.Equals(characters[i], "aa")))
{
//MessageBox.Show("a");
valueOfDictOne = dict1[characters[i].ToString()];
list.Add(valueOfDictOne);
}
else if (String.Equals(characters[i], "aa"))
{
//MessageBox.Show("aa");
valueOfDictOne = dict1[characters[i].ToString()];
list.Add(valueOfDictOne);
}
}
catch
{
list.Add(characters[i].ToString());
}
}
...
Please help me to correct this code or please provide any easy alternative ways to transliterate.
Thank you.