Unicode strings in .Net with Hebrew letters and numbers

前端 未结 4 1399
梦如初夏
梦如初夏 2021-02-04 15:38

There is a strange behavior when trying to create string which contains a Hebrew letter and a digit. The digit will always be displayed left to the letter. For example:

<
4条回答
  •  Happy的楠姐
    2021-02-04 15:59

    That strange Behavior has explanation. Digits with unicode chars are treated as a part of unicode string. and as Hebrew lang is read right to left, scenario will give

    string A = "\u05E9"; //A Hebrew letter
    string B = "23";
    string AB = A + B;
    

    B comes first, followed by A.

    second scenario:

    string A = "\u20AA"; //Some random Unicode.
    string B = "23";
    string AB = A + B;
    

    A is some unicode, not part of lang that is read right to left. so output is - first A followed by B.

    now consider my own scenario

    string A = "\u05E9";
    string B = "\u05EA";
    string AB = A + B;
    

    both A and B are part of right to left read lang, so AB is B followed by A. not A followed by B.

    EDITED, to answer the comment

    taking into account this scenario -

    string A = "\u05E9"; //A Hebrew letter
    string B = "23";
    string AB = A + B;
    

    The only solution, to get letter followed by digit, is : string AB = B + A;

    prolly, not a solution that will work in general. So, I guess u have to implement some checking conditions and build string according the requirements.

提交回复
热议问题