Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Left-To-Right Mark not working in Swift

Tags:

ios

swift

unicode

I'm trying to use LRM in order to make a string properly displays in arabic. My string is as follows:

Percentage is: 32.12%

However on arabic it displayed as:

%32.12 :نسبة ط

So far so good. On objective-c I've used in the past following markup to fix this problem:

[NSString stringWithFormat:@"\u200E %@", value]

But when I try it on Swift it just didn't move the percent:

"\u{200E}\(value)"

Am I using unicode characters wrong in Swift or I made mistake somewhere else?

like image 925
hris.to Avatar asked Feb 09 '23 10:02

hris.to


1 Answers

The below should be a comment on the question, really, but I need the formatting...

I do this in a Playground (Xcode 7 beta 4)

let value = "32.12%"
print("نسبة ط:\u{200E}\(value)")

And it prints

32.12% :نسبة ط

Is that what you want?

Also

let value = "\u{200E}32.12%"
print("نسبة ط:\(value)")

works the same. This is in the Playground. Are you using an older version of Xcode perhaps?

like image 150
JeremyP Avatar answered Feb 20 '23 11:02

JeremyP