How to use String(format:)
in Arabic string in Swift?
let seconds = 458569
my code is:
let arabicStr = "لديك ٪d ثانية متبقية للاتصال"
let Str = String(format: arabicStr,seconds)
and output:
لديك d٪ ثانية متبقية للاتصال
How to use String(format:)
in Arabic string in Swift?
let seconds = 458569
my code is:
let arabicStr = "لديك ٪d ثانية متبقية للاتصال"
let Str = String(format: arabicStr,seconds)
and output:
لديك d٪ ثانية متبقية للاتصال
Try this code.
let seconds = 458569
let Str = "لديك \(seconds) ثانية متبقية للاتصال"
print(Str);
OR
let Str2 = String(format: "لديك %d ثانية متبقية للاتصال",seconds)
print(Str2);
The has nothing to do with used -Arabic- language. When using init(format:arguments:)
, the format should be a valid string format specifier:
let seconds = 458569
let Str = String(format: "لديك %d ثانية متبقية للاتصال",seconds)
Note that it should be %d
instead of d%
, which means that this specifier describes:
Signed 32-bit integer (int).
On the other hand:
Since you are working with Swift strings, you could also achieve it by implementing a string interpolation as mentioned in AtulParmar`s answer.