views:

354

answers:

0

I am working on html documents using WebBrowser Control, I need to make a utility which searches a word and highlights it in the browser. It works well if the string is in English, but for strings in other languages for example in Korean, it doesn't seem to work.

The Scenario where the below mentioned code works is-

Consider user has selected a word "Example" in the Webpage, now I need to highlight this word and all its occurences. Also I need to calculate their byteOffset (the code snippet does that only).

Now for English language the below code works fine but for languages like Korean it does not workd at all.

its not getting inside the for-each loop foreach (Match m in reg.Matches(this._documentContent))

here _documentContent contains the webpage source as string. occurenceNo is the no. of occurence of selected word in the document

I need some help/suggestion on handling this issue..??

Here's the code--

'HERE strTemp is the string that contains Korean string

         string strTemp = myRange.text;
         string strExp =@">(([^<])*?)" + strTemp + "(([^<])*?)<";

            int intCount =0;
            Regex reg = new Regex(strExp);
            Regex reg1 = new Regex(strTemp);
            foreach (Match m in reg.Matches(this._documentContent))
            { 
                 string strMatch = m.Value;
                 foreach (Match m2 in reg.Matches(strMatch))
                { 
                    intCount += 1;
                    if(intCount==OccurenceNo)
                    {
                        int intCharOffset = m.Index + m2.Index;
                        System.Text.UTF8Encoding d = new System.Text.UTF8Encoding(); 
                        int intByteOffset = d.GetBytes(_documentContent.Substring(1, intCharOffset)).Length;

                    }
                }

            }