How to transliterate on c# .net 4.0? -
i new programming. these 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 = ""; (int = 0; < 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 array. (no of characters typed in text box)
my expected output should be:
if user types -> output should அ.
likewise:
a -> அ
aa -> ஆ
a -> ஆ ...
note aa & represent same ஆ
my problem: code replace 1 charecter (a -> அ), works fine.
but if type aa output அஅ
aa -> அஅ
but need correct output as
aa -> ஆ
i have added lines of codes this. did not work:
... (int = 0; < 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 me correct code or please provide easy alternative ways transliterate.
thank you.
you can use simple parser/lexer tokenize input string. thanglishtotamillist
function like:
... textreader r = new stringreader(characters); lexer l = new lexer(r, defs); while (l.next()) { list.add(dict1[l.tokencontents]); } ...
you can find example of simple parser/lexer here: poor man's "lexer" c#
it overkill problem, should job done.
Comments
Post a Comment