how to find exact location point() of characters in mixed language sentence


  • hi

    location of character in mixing  laguage (e.g.  farsi & english) sentence are different in memory and display , you can check it with point() 

    all  Instructions as LEFT ,RIGHT ,MID not work  correctly when using it on the mix language
    also GetPositionFromCharIndex(I) also not get position of the char user see on display...
    i need to have exact location point() of display character (from left or right side of text box)

    2012年4月10日 20:32


  • I don't understand. Can you please give an example?


    2012年4月11日 0:01
  • Hi Armin

    in quick basic String is a literal of character and in sting is an output of function which act on array of character , and if this character are mix language then made a sentence according complex instruction  out of hand of programer !!

    Sentence: The World دنیا در 23/01/91 زیباترست

    "د" is the farthest and "T"  is first character from left of above sentence

    if get index , you find   "د"  on index  11 and poin.x 89 ....

    this means function point take location of "د" form memory not from farthest as can seen on display,i need to find point.x=281  for chrarcter "د"      not 89 ,how to find it ?

    2012年4月11日 6:50
  • You say "mix language". The String does not care about the language. In VB.Net, Strings are a sequence of UTF-16 encoded Unicode characters. Every Char object is an unsigned 16 bit value. The value is the Unicode code point of the character. Therefore, the number of Char objects is usually equal to the number of characters in the String.

    There is an exception if the Unicode code point >=0x10000. In this case, two Char objects are used to represent one Unicode character. They are then called surrogates (low- and high-surrogate).

    Anyway, I must admit that I was not aware of this special String handling. I know that you can change the RightToLeftDirection for a control, but I didn't know the direction can change within a String itself. Therefore, thank you for the example. Again I've learned something interesting. However, this does not help you. As this is a feature of the function String.GetPositionFromCharIndex, the best place to ask is in a .Net Framework forum because it affects all .Net Framework programmers, not only VB. There you might also find more specialists about it.

    Though I will continue research on how this is handled and will report later.


    2012年4月11日 11:26
  • For illustration:

    The Panel at the bottom shows the characters at the location as it is returned from String.GetPositionFromCharIndex. I've scaled the X value by 5 because characters cover each other. Below each character, you see the index within the String. I'm using three lines for the index because some indexes cover each other (like 18 and 26). 

    Regarding your question: I understand now. Character "د" is at index 10 (not 11 because it starts with zero), but in the panel it is shown in a different location than in the Textbox above. That means, GetPositionFromCharIndex returns the wrong value. This seems to be a bug.

    There is a central place where we can report bugs:

    I have searched for GetPositionFromCharIndex and got two results. None of them covers this problem. Therefore I suggest you open a new bug report. There you can also point to this thread. Good luck with it!

    EDIT: For better readbility, open the picture above in a new tab or window as it's scaled down within the message.


    2012年4月11日 11:50
  • As GetPositionFromCharIndex is a wrapper for sending EM_POSFROMCHAR, I've tried the latter, too. It returns the same values as the method. So it is also not a Framework issue, it's a problem in Windows itself.

    EDIT: Yarmini, I will ask your question at

    providing the information I already have.


    2012年4月11日 13:21
  • hi Armin
    you forgot to advise problem about Left, Mid ,and Right these instruction is very important for text control program ,but all of them not work in mixed laguage text
    in your example you should drow  char according  index not acording point
    point is incorrect ! ,for better drow you should using courier font 
    Armin your date is reverse !

    Microsoft should design getcharposition at render time not at string making point ! to solve these problem

    Armin ,am yarmini , not a guy !!

    2012年4月12日 21:05
    • "you forgot to advise problem about Left, Mid ,and Right "

    I did not forget it. I focused on one problem at a time. EDIT: In the windows ui forum, they don't care about Left, Mid and Right.

    • "in your example you should drow  char according  index not acording point point is incorrect !"

    Of course it is wrong. That's the purpose of the example. You have described it in words, but for better understanding, I've visualized it.

    • "Armin your date is reverse !"

    I have copied your sample text from the browser to the Textbox. It looks equal. The drawing in the panel is also equal (only the "2" is at the wrong location, but that's the problem). This is a screenshot from your message straight from the browser.

    If you compare it to the screenshot from my test application, the Textbox looks equal. Therefore I don't know what "your date is reverse" means.


    2012年4月12日 21:43
  • The problem has been identified previously in this place.  I can't now find the item, but as far as I can remember there was no solution provided at that time (other than don't mix you left/right strings!)
    2012年4月12日 22:03
  • Regarding Left, Mid, Right, I don't know what you consider the right result. This is the order of the chars as returned from the Mid function, the String's Chars property and the String's SubString method: (All three functions return the same result)

    00: 0054 T
    01: 0068 h
    02: 0065 e
    03: 0020  
    04: 0057 W
    05: 006F o
    06: 0072 r
    07: 006C l
    08: 0064 d
    09: 0020  
    10: 062F د
    11: 0646 ن
    12: 06CC ی
    13: 0627 ا
    14: 0020  
    15: 062F د
    16: 0631 ر
    17: 0020  
    18: 0032 2
    19: 0033 3
    20: 002F /
    21: 0030 0
    22: 0031 1
    23: 002F /
    24: 0039 9
    25: 0031 1
    26: 0020  
    27: 0632 ز
    28: 06CC ی
    29: 0628 ب
    30: 0627 ا
    31: 062A ت
    32: 0631 ر
    33: 0633 س
    34: 062A ت
    The second column is the character code.


    2012年4月12日 22:08
  • hi Armin

    Dim Jk As String = "The World دنیا در 23/01/91 زیباترست "

    Dim JkL As String = Left(Jk, 15) 'The World دنیا

    Dim JkR As String = Right(Jk, 8) 'دنیا د 

    Dim JkM As String = mid(Jk,10, 8) 'زیباترست

    as you can see Jk is main sentence ,TkL is left JkM is mid and JKR is right side

    i write result after ' all of result is incorrect
    with left i should see "The World اترست"
    with Mid i should see "ترست"
    with right  i should see "دنیا در"
    i explained  you befor all function act on string in memory
    char arranged  in  memory  according its law ,(which design by unicode consortium)
    date means solar date (formal date of iran 91/01/23)
    if  you are not familiar with farsi ,how you read my sentence !!  


    • 編集済み yarmini 2012年4月14日 0:48
    2012年4月13日 23:12
  • if  you are not familiar with farsi ,how you read my sentence !!  


    I'm not sure what this means. No, I'm not familiar with Farsi, though I think I helped illustrating the problem and narrowing it down to not being VB or Framework specific. Am I right? In addition, I'm interested in issues that are new for me in order to learn something, in this case from a different culture. I think it helps understanding each other better.

    Further more, I was trying to understand the problem you have with the Mid/Left/Right statements which was not clear right away. I think many people are not familiar with the question you have, so every step into clearing it up should be helpful. It makes it easier also for other members to jump into the discussion and give support. Don't you agree?

    I'm sorry if you didn't get the final solution you were asking for.


    2012年4月14日 0:24
  • Hi Acamar (Mcc)

    i don't mix ,my customer try to use mix language and our  books have many mix sentence , you should solve problem ...
    i am wrote editor for farsi(ansi)20 years ago ,in that editor ,user only change font key ,My app  automaticaly write right to left (for farsi))and   write left to right (for english)  on a line  , (without separating  english and farsi, mix ) , it is  working very well without any problem ,because in Dos mode String is a literal of character inside "" mark,in  string is a complex function, if i have ability to using string as a literal character(not as a complex function),not difficult to write editor for unicode , please send my suggestion to proper division ,i am ready to do

    2012年4月14日 0:41
  • Mid/left/right does not refer to the location on the screen, if that was your question. That's by design.


    2012年4月14日 0:57
  • IMO, you can use the caret(the vertical txt inersion point) to position the char you want to locate by using the SelectionStart property of TextBox.  And if you want the point of the char relative to the entire screen, you can use this method called PointToScreen().  As for the point value, you must first obtain the point value of char and then use that method to get its screen location instead of the location in the client app.

    I don't know if this can help you, hope it helps.

    My blog:

    2012年4月14日 6:40
  • Hi horngsh,

    "you must first obtain the point value of char"

    thought about that too, but it requires GetPositionFromCharIndex to work correctly. Unfortunately it doesn't (IMO).


    2012年4月14日 10:20
  • Dear  Armin

    that was  a joke only , because you want to contribute to solve the problem carefully, sorry , my English is not so good, however I thank your side! 
    correct date is 91/01/23 not 23/01/91
    you can see the problem during  manipulating(fetch) a word from a sentence in mix language
    left\right\mis not work correctly

    2012年4月14日 10:42
  • Yarmini,

    thanks a lot for the clarification. :-) My English is also not the very best, so misunderstanding can be from my own deficiencies.

    Unfortunatelly, I'm unable to give further help from this point as my knowledge is limitted in this area. Anyway, good luck for you!


    2012年4月14日 11:12
  • hi Horngsh
    point to screen  is using for coloring some char on the client screen ,i need to chang or modifing any word of sentence befor showing it to client screen ,this is a location of sentence which ready to send to screen ?
    this location is not location of string in memory ? and all of  statement (left/right/mid/point) should use pointer  to that location not pointer  to string location ,i suggest naming that location as string output location!!


    2012年4月14日 11:50
  • Hi yarmini:

    I don't know farsi language at all.  Besides it is read from right to left. Is there anything else special that we should pay attention to?  Actually I am not quite getting what your question means a little bit.  Could you elaborate a little bit?

    My blog:

    2012年4月16日 13:01
  • hi Horngsh
    english is LTR and farsi is RTL ,also  farsi digit is LTR ,unicode string no problem

    if you write sentence  completly  english (LTR) or writing completly Farsi (RTL)

    but in actual ,  you need to write in a sentence  include Farsi word(RTL) and farsi digit(LTR) or you may want to add english word (LTR) inside that sentence

    arangement of these word (we say complex sentence) on screen is different with memory !!

     you can read carefully my detail explanation history above ...
    are you know why char arangement are different in display and memory ,if you know please give me refernce document ?
    if you know string ouput location(i mentioned before)  ,please give me refernce document


    2012年4月18日 0:39
  • are you know why char arangement are different in display and memory ,if you know please give me refernce document ?

    You wrote yourself that the order must be mixed on the screen (LTR/RTL) so that you have readable text. If the order on the screen was equal to the order in memory, you probably couldn't read the text on the screen.


    2012年4月18日 1:34
  • hi  Armin ,I hope you comeback

    this means have a function reading memory and making readable text ,then writing to display...
    in Msdos display area start from  &HB800 ,we need to access the display area in windows!!

    ,may in this area can find correct char sequence 

    ,I named it: string out put ,if available !


    2012年4月18日 23:28
  • I understand what you mean. This is not available in Windows. You must admit that even in MSDOS, you did not store the characters in screen memory. You stored text somewhere else in memory before output to the screen. In which order has it been stored? In which order are characters stored in a file? I guess they are not stored in the  same order as they appear on the screen.

    In my opinion, the character order within a String is correct. Also, screen output is correct.

    The only (big) problem is that GetPositionFromCharIndex does not work correctly. I'm afraid, I can not solve it. Unfortunatelly, there was no answer in the Windows forum yet. I do not know to whom to address this issue.


    2012年4月18日 23:49
  • Hi Armin
    i request a new way to solve issue ,during refresh of display any element reproducing

    this means text elements sequentially made and sending to display location 

    during refresh can save a copy of text element in the char array ? !
    this Means can redirecting text element to array not to display


    2012年4月19日 20:27
  • Hi Yarmini,

    I'm afraid, I see no way to do this.


    2012年4月20日 0:05
  • 2012年4月20日 0:23
  • Hi armin

    i read all you reference ,but you know ,i am developer ,if i try to using that ,i must be going to learn   C++ first !!

    how can using  "GetTextExtentExPoint " in vb ?
    I known  many thing  abot font and glyph (i designed farsi font for Dos ,20 years ago)...
    at current time i need help for ,anyway

    i ask another way for solving issue
    we can get char array of string ...
    have a function to rearrange elements of this array  according the sequence of char of "WYSIWYG " ?


    2012年4月20日 22:52
  • Hi Yarmini,

    if you read the topics before and after the linked one, you get more information. I think you have to read it all to understand it completely (I didn't do it) and find the appropriate functions. I'm pretty sure there will be a way to find it out. Uniscribe looks promising.

    For using the functions, you don't need C++. Just Declare the functions (see VB's Declare statement).


    2012年4月21日 0:43
  • --------------------------------------------------------------------------------
    Hi Armin congratulation
    never afraid ! i find solution in anther planet (in he unicode site ) goto this address

    this usable for you not for me ! as you know i need this ability inside visual studio environment ,because i need it ability to using functions MID LEFT RIGHT working correct ,Now ball in your ground !!
    thanks Yarmini

    2012年5月12日 10:05
  • Hi Armin
    i don't know who mark this thread as answer ?!!
    not yet answer ,i looking microsoft engineer to solve this problem ,anyway not answer ,i only show you a roadmap !!, to staring preparing answer

    best regard


    2012年5月13日 0:07