2

I need to split the following string into string[].

string tempstring = "د.ع.‏123,456.00";// culture "ku-Arab-IQ"
string[] temp = tempstring.Split(".".ToCharArray());

But I am getting the following answer:

{string[4]}
    [0]: "د"
    [1]: "ع"
    [2]: "‏123,456"
    [3]: "00"

I expect the answer to be like:

{string[4]}

[0]: "‏123,456"
[1]: "00"
[2]: "د"
[3]: "ع"

Edit: But the above-mentioned splitting works fine for the string "123,456.00 د.ع.‏" (Culture - "ar-IQ") Result:

 {string[4]}
        [0]: "123,456"
        [1]: "00 د"
        [2]: "ع"
        [3]: "‏"

I think both of the strings are RTL text, but splitting results differ in both cases. Could you please help me, how to split this string properly. or whether this is the correct splitting.

Venkat
  • 2,549
  • 2
  • 28
  • 61
  • 1
    I don't think you expectation is expected... (Almost mandatory https://xkcd.com/1137/). Some good reasoning why you think you should be getting different result with RTL string would be welcome improvement. – Alexei Levenkov Mar 20 '18 at 06:12
  • 1
    Possible duplicate of [Parsing through Arabic / RTL text from left to right](https://stackoverflow.com/questions/12630566/parsing-through-arabic-rtl-text-from-left-to-right) – Gaurang Dave Mar 20 '18 at 06:17
  • @GaurangDave: I will check the shared question and close this if it is working for my case. – Venkat Mar 20 '18 at 06:27
  • 1
    `123,456.00 د.ع.‏` IS NOT EQUAL TO `د.ع.‏123,456.00`. It has space symbol between `00` and `.`, so it splits in differ way. Now, you have 2 different words – Backs Mar 20 '18 at 10:33

1 Answers1

4

This string contains right to left substrings, so, you get correct result.

د is the first substring, because it's right to left,

ع is the second by the same reason

‏123,456 is usual left to right string, so it's third

00 is forth

Backs
  • 24,430
  • 5
  • 58
  • 85
  • Thanks for the explanation. I have edited the question slightly. – Venkat Mar 20 '18 at 10:13
  • @Venkat what do you want to get after splitting? – Backs Mar 20 '18 at 10:13
  • I have added two example strings in the questions, I think both are RTL. One string results like you explained in the above answer, the second one results like the one I expected in the question. So Please share whether the splitting is proper or anything I am missing. Thanks. – Venkat Mar 20 '18 at 10:23
  • @Venkat you will never get result as you expect for RTL strings. So, what is your question? `string.Split` is working well – Backs Mar 20 '18 at 10:27