2

I'm not sure how to title this issue. My app uses .regx for localization, and some of the strings have {0-9} tags and are fed to string.Format. It worked well, until I received the first RTL translation. string.Format crashed, complaining that the string's format was incorrect. Here is an example of a crashing string:

"{اعاده تسميه "{0

It looks correct, but the {0} is actually split in half - it's a mix of RTL and LTR text. You can see the issue by selecting and dragging your mouse over the string.

I'm trying to fix these in bulk (make whole value RTL), but it's proven to be surprisingly hard to do (and extremely frustrating). Is there any good way of fixing this?

Klocman
  • 432
  • 4
  • 12
  • The problem is the bytes in the string look like the string starts with `"{` and ends with `"{0`. I'm not fluent in Unicode, but [Parsing through Arabic / RTL text from left to right](https://stackoverflow.com/q/12630566/580951) suggests using a Left-to-Right mark (U+200E) to separate out the Arabic. – Dustin Kingen Oct 06 '17 at 20:44

1 Answers1

-1

string.Format() does not matter to the source string or parameters. For example consider following:

string.Format("لغه العربیه {0} زبان فارسی {1} کشور افغانستان {2}", p1, p2, p3);

Any string can set in p1, p2, p3, any right-to-left or left-to-right string. Also opoosite way works too. I mean main string being a left-to-right string and parameters being left-to-right or right-to-left.

An important point here is that text direction is a matter of UI not string itself. A UI component may want to show a string as right-to-left or left-to-right.

Afshar Mohebi
  • 10,479
  • 17
  • 82
  • 126
  • Your example works because the order is still correct - the opening bracket is still next to the rest of the tag. string.Format("{معالجه {0 ", p1) throws 'System.FormatException' in mscorlib.dll Additional information: Input string was not in a correct format. – Klocman Oct 14 '17 at 21:55
  • You may use `string.Format("معالجه {0}", p1)` it should not throw any exceptions. In this case, literal `"معالجه"` comes before parameter `{0}` – Afshar Mohebi Oct 15 '17 at 07:24