Wrong Law Left Concatenation English and Arabic

I am trying to combine an English string with an Arabic string

string followUpFormula = "FIF"; string renewAbbreviation = "ุน.ุช" ; string abbreviation = followUpFormula +"-"+ renewAbbreviation; var result = 10 + "/" + abbreviation + "/" + 2016; 

the result is 10 / FIF- ุน.ุช / 2016 but I want to show them as follows: 10 / FIF- ุน.ุช /
2016

How can i do this? thanks

+5
source share
2 answers

A couple of additions to your code

 string followUpFormula = "FIF"; string renewAbbreviation = "ุน.ุช" ; string abbreviation = followUpFormula +"-"+ renewAbbreviation; var lefttoright = ((Char)0x200E).ToString(); var result = 10 + "/" + abbreviation + lefttoright + "/" + 2016; 

Char 0x200E is a special character that reads the following text, read from left to right, see here for more information about the character.

Char 0x200F switches to the format from right to left.

+3
source

This is due to how unicode rules handle mixing LTR and RTL text. You can override the default behavior by explicitly using special characters that indicate the intention to directly insert RTL or LTR text:

 private const char LTR_EMBED = '\u202A'; private const char POP_DIRECTIONAL = '\u202C'; private string ForceLTR(string inputStr) { return LTR_EMBED + inputStr + POP_DIRECTIONAL; } private void Form1_Load(object sender, EventArgs e) { string followUpFormula = "FIF"; string renewAbbreviation = "ุน.ุช"; string abbreviation = ForceLTR(followUpFormula + "-" + renewAbbreviation); textBox1.Text = 10 + "/" + abbreviation + "/" + 2016; } 

This places the embedded character from left to right (U + 202A) in front of the line and follows it using the Pop-Directional-Formatting character (U + 202C). The latter removes the built-in directional formatting hint and returns the direction of the text to what it was in the previous context. Thus, the returned string is safe to use in the context of RTL or LTR.

The parsing rules for LTR and RTL in various contexts are extensive and complex. For reference, you can find the specification of the bidirectional algorithm here . Certain characters are classified as โ€œweakโ€ or โ€œstrongโ€ in terms of their proximity to LTR or RTL contexts. Things like / and - are weak, so you have to be explicit when mixing them regarding the direction of the text and layout you like for these characters.

+2
source

All Articles