I want to find the position of a certain character (used as a delimiter) in a C# string, which may be in a language supporting right-to-left text direction (like arabic or hebrew), and I want to get that index ignoring that direction.
For example, I have:
var name = "שרון^דבורה";
var index = name.IndexOf('^', 0); // index = 4, expected 5
This name has 5 characters on the left of the delimiter, and 4 on the right.
The resulting index is 4, because the whole string is seen as hebrew and read from right to left, but I want to get the index from the left as saved in the string (for the curious: this is about encoding PersonName values in DICOM). Using invariant culture does not change this. I also tried detecting the text direction and adapt the found value accordingly, but also didn’t find an easy way to do this (and that would be ugly, too).
I’m quite sure that there is an easy way to achieve this, but I haven’t found it so far.