I'm trying to append some numbers to a string, that string already contains Persian character and StringBuilder
always appends Persian number to the string.
StringBuilder sb = new StringBuilder();
sb.Append( other things );
sb.Append("', '");
sb.Append("1234234");
sb.Append("', ");
Even when I'm explicitly using English numbers like ones in the above code, I still end up with Persian numbers. How can I append English numbers to this string?
UPDATE
These lines simulate my problem, you can see the Persian number by tracing this code:
StringBuilder temp = new StringBuilder();
temp.Append("INSERT INTO [db] (....) VALUES ('21211221', 111555,
'2015/12/12', 'نام خانوادگی ', 'اتاق چهار تخته");
temp.Append("', '");
temp.Append("234234");
The last append should be an English number, but it's not.
As @Jon-Skeet said, it is a problem of renderer. Windows text rendering engine becomes confused after getting persian characters and continues to append following text in RTL order. Thus we need to help renderer to proper render appended text in LTR order. For that we can append Unicode Left-to-right symbol 'U+200E' after persian text.
StringBuilder temp = new StringBuilder();
temp.Append("INSERT INTO [db] (....) VALUES ('21211221', 111555, '2015/12/12', 'نام خانوادگی ', 'اتاق چهار تخته");
temp.Append('\x200E');
temp.Append("', '");
temp.Append("234234");
Without LTR symbol:
INSERT INTO [db] (....) VALUES ('21211221', 111555, '2015/12/12', 'نام خانوادگی ', 'اتاق چهار تخته', '234234
With LTR symbol:
INSERT INTO [db] (....) VALUES ('21211221', 111555, '2015/12/12', 'نام خانوادگی ', 'اتاق چهار تخته', '234234
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With