5

I'm currently using string format. Works perfectly in my other languages but I am having trouble with Hebrew.

var msg = string.Format("{קיבלת בקשה חדשה להפנייה מ{0} ו {1} {2", "test1", "test2", "test3");

this crashes and the hebrew text is underlined saying this is an invalid placeholder.

May I ask how do I handle hebrew text with String.Format

Phoenix
  • 467
  • 4
  • 18
  • 1
    Interesting question, `foreach (char c in "{קיבלת בקשה חדשה להפנייה מ{0} ו {1} {2") Console.WriteLine((int)c);` gives a truly weird result – Adriano Repetti Jan 24 '19 at 18:15
  • I can't try with my keyboard without going mad but maybe the problem is in the input method more than `String.Format()`. Try to concatenate (I know, I know...) the string (note that at first when you type { in RTL you get }): `Console.WriteLine(string.Format("{2} {1}" + "יבלת בקשה חדשה להפנייה מ" + "{0}"+ "ו", "test1", "test2", "test3"));` seems to work. – Adriano Repetti Jan 24 '19 at 18:25
  • @AdrianoRepetti I can't use concatenation, that string to format changes very frequently. – Phoenix Jan 24 '19 at 18:26
  • The problem seems to be that there is a bidi Marker inside your {2} token. Try deleting the token and pasting {2} back in. – Chronocide Jan 24 '19 at 18:29
  • @Chronocide Sorry, I am confused. If there was a token there, wouldn't you see it. Or couldn't you have pasted it as an answer? I personally am not sure what token you are referring to that's within {2} – Phoenix Jan 24 '19 at 18:33
  • 1
    Can you **insert** an RTL markerat the very beginning of the string? It seems that the very first character is interpreted as LTR and everything else as RTL – Adriano Repetti Jan 24 '19 at 18:37
  • @Phoenix Chronocide is talking about an invisible character that some RTL IMEs inserts at the beginning of a string to _say_ it's RTL. VS should strip them out (and they should be at the beginning of the code line, not in the middle). There are also some "temp override" RTL/LTR markers. It might happen to get them when copy & paste a string from somewhere else but I didn't see any in your string. I'd tend to consider this a weird thing in the IME we're using (_western_ characters and RTL characters don't mix that well in Windows) – Adriano Repetti Jan 24 '19 at 18:42
  • @Phoenix no you wont see the character it is a non printing character that controls the direction of text. https://en.wikipedia.org/wiki/Bi-directional_text The following should work: ` "קיבלת בקשה חדשה להפנייה מ{0} ו {1} {2}" ` – Chronocide Jan 24 '19 at 18:43
  • I've pasted the code into my IDE and it appears there are some direction change characters in there. I suspect there might be a bug in the compiler's string handling. Can you try it with a simpler string? – Neil Jan 24 '19 at 17:45
  • I did say it works perfectly in other languages and I'm only trying to solve it for hebrew. Hebrew is from RTL. – Phoenix Jan 24 '19 at 17:48
  • From your IDE, if you put the cursor on the first character of the string, then press right, right right (etc), does the cursor jump around, rather than stepping through the characters? It jumps around on mine, which suggests there are some unicode direction change characters in there. – Neil Jan 24 '19 at 17:50
  • Yes, it does. Probably because it's RTL – Phoenix Jan 24 '19 at 17:55

2 Answers2

0

Try to use string interpolation

var test1 = "test1";
var test2 = "test2";
var test3 = "test3";
var msg = $"{test3} {test2} ו {test1} קיבלת בקשה חדשה להפנייה מ";
NaDeR Star
  • 647
  • 1
  • 6
  • 13
0
     // 1
    string msg1 = $"{"קיבלת בקשה חדשה להפנייה מ"} {"test1"} {"ו"} {"test3"} 
    {"test2"}";

    // 2
    string test1 = "test1";
    string test2 = "test2";
    string test3 = "test3";

     // 2.1
    string msg2 = $"קיבלת בקשה חדשה להפנייה מ{test1} ו {test3} {test2}  ";
    // 2.2
    string msg3 = $"{"קיבלת בקשה חדשה להפנייה מ"} {test1} {"ו"} {test3} {test2}";


    // 3
    string startMessage = "קיבלת בקשה חדשה להפנייה מ";
    string continueMessage = "ו";

    // 3.1
    string msg4 = string.Format("{0} {1} {2} {3} {4}", startMessage, test1, 
     continueMessage, test3, test2);
    // 3.2
    string msg5 = $"{startMessage} {test1} {continueMessage} {test3} {test2}";