Click here to Skip to main content
15,748,477 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
a VERY!HARD _Question:_
It will take a while to explain it!
I am making a dictionary eng-rus (English-Russian).
I made 2 textboxes, one for writing words in eng, and another to write in rus.

the engTOrus textbox is quite simple...
When a eng char from array(literaEng) is typed in textEng(textbox), quickly is converted in the rus kind of char from literaRus array and is put inside textrus(textbox).
And for special combinations is working pretty well too(like ie,io,etc)
here is the simple code:
      string[] literaRus = new string[33] { "е", "ё",/**/"ц", "ч",/**/"ш", "щ", "ы",/**/"ю", "я", "а", "б", "в", "г", "д", "ж", "з", "и", "й", "к", "л", "м", "н", "о", "п", "р", "с", "т", "у", "ф", "х", "ъ", "ь", "э" };
      string[] literaEng = new string[33] { "ie", "io", "tz", "ce", "sh", "ci", "ii", "iu", "ia", "a", "b", "v", "g", "d", "j", "z", "i", "y", "c", "l", "m", "n", "o", "p", "r", "s", "t", "u", "f", "h", "~", "`", "e" };
bool engisActive = false, rusIsActive = false;
      private void textEng_Click(object sender, EventArgs e)
          engisActive = true; rusIsActive = false;
      private void textEng_TextChanged(object sender, EventArgs e)
          if (engisActive)
              textrus.Text = textEng.Text;
              for (int i = 0; i < literaEng.Length; i++)
                  if (textrus.Text.Contains(literaEng[i]))//lower
                      textrus.Text = textrus.Text.Replace(literaEng[i], literaRus[i]);
                  if (textrus.Text.Contains(literaEng[i].ToUpper()))//upper
                      textrus.Text = textrus.Text.Replace(literaEng[i].ToUpper(), literaRus[i].ToUpper());

Now I have to make the same thing but backwards.
What the next code do(and should but it does not):
When I type inside textrus(textbox), I type with regular characters (English ones). Now, when this textrus see a normal char, it rapidly convert it into it's rus form of char, right? Once the text inside it is converted, I can copy to textEng only the rus converted chars.
And here is the question:
How can I copy the normal characters (and the whole text in eng), from textrus(textbox) into the textEng(textbox), after that, let it convert to rus chars, and when I must type the next char in textrus, he must allow me to see both its past converted chars(rus ones) and in the same time the new eng char(converting them as I am typing), then converting them again in eng for the textEng, and re convert to rus.

Right now, the next code transforms only the rus chars i can put there into eng chars.(into textEng(textbox)) --- but when I write eng chars inside textrus, it is not converting anything in rus chars. How to do that?

PFFFFFFFFFFF.... its very hard to explain, though I have it very clear in my mind what i should do. Thanks and I hope I was "clear" enough. :)

here is the HARD code:
//same arrays
        string[] literaRus = new string[33] { "е", "ё",/**/"ц", "ч",/**/"ш", "щ", "ы",/**/"ю", "я", "а", "б", "в", "г", "д", "ж", "з", "и", "й", "к", "л", "м", "н", "о", "п", "р", "с", "т", "у", "ф", "х", "ъ", "ь", "э" };
      string[] literaEng = new string[33] { "ie", "io", "tz", "ce", "sh", "ci", "ii", "iu", "ia", "a", "b", "v", "g", "d", "j", "z", "i", "y", "c", "l", "m", "n", "o", "p", "r", "s", "t", "u", "f", "h", "~", "`", "e" };
     private void textrus_Click(object sender, EventArgs e)
            rusIsActive = true; engisActive = false;
        private void textrus_TextChanged(object sender, EventArgs e)
            if (rusIsActive)
                textEng.Text = textrus.Text;
                for (int i = 0; i < literaRus.Length; i++)
                    if (textEng.Text.Contains(literaRus[i]))//lower
                        textEng.Text = textEng.Text.Replace(literaRus[i], literaEng[i]);
                    if (textEng.Text.Contains(literaRus[i].ToUpper()))//upper
                        textEng.Text = textEng.Text.Replace(literaRus[i].ToUpper(), literaEng[i].ToUpper());

I have an idea but im not so sure of it....using some kind of list/array algorithm, but im not so certain of its validity.
Updated 26-Nov-11 14:11pm
[no name] 26-Nov-11 5:40am    
please remove a VERY!HARD _Q_ on your title to make the question clear.
_Q12_ 26-Nov-11 5:43am    
[no name] 26-Nov-11 5:47am    
Thanks :)
Addy Tas 26-Nov-11 18:32pm    
If i'm reading it correctly you want to transform russian in english chars to russian chars to convert them back to english chars. Am i correct here? If so why don't you eliminate two transformations and be done with it?
_Q12_ 26-Nov-11 20:08pm    
well, the rus textbox must render rus text, and the eng one must render eng text. Now, when I write something inside rus textbox, I write it in [1]eng, it must then convert it back(at run time) in [2]rus. When I write with eng chars, it must copy all text from rus textbox and paste it inside eng textbox. But the rus textbox already contains rus chars... so I must convert all text from there in eng, to be able to transfer it into eng textbox. After conversion, it must reconvert back into rus. :)
That's the general idea.

1 solution

I didnt spent a lot of time on your code but i think it should be really easy to implement it this way:
1. Two function one for each textbox.(text change)
2. Two char arrays, one for each textbox. On text change load chars to coresponding array (english input for example puts it into "english" array) than go char by char and put (or not if it is not in corresponding eng-rus,rus-eng dictionary) translation to the other array. Print string to textbox.
Share this answer
_Q12_ 24-Nov-11 17:00pm    
It's exactly what I've done so far. For eng, is simple to implement, for rus is quite challenging because it must support English, then convert to rus; and when I type in it, must store somehow the rus text, let it printed there, and only what I type must be converted on the fly.
I use only 2 Global arrays.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900