i am trying to concat arabic text with english text for example :
let pdfName = "\(name)_copy_1234.pdf"
name is like : وصغار
1234 is my random number
But in document folder it is saving like this : copy_35679_وصغا.pdf
i am trying to concat arabic text with english text for example :
let pdfName = "\(name)_copy_1234.pdf"
name is like : وصغار
1234 is my random number
But in document folder it is saving like this : copy_35679_وصغا.pdf
You need to properly escape the beginning and the end of your pdfName
string, as seen here:
let name = "وصغار"
let pdfName = "\u{202A}\(name)_copy_1234.pdf\u{202C}"
print(pdfName)
// English وصغار_copy_1234.pdf
// Arabic وصغار_copy_1234.pdf
Apple discusses it here, but the code is for Objective-C, so it does not show how to properly enclose it for Swift with { }.
This is not a Swift-specific issue, as it is baked into the Unicode standard and is related to the way that Unicode supports bi-directional scripts (e.g. Latin and right-to-left scripts such as Arabic). Consider reviewing a detailed explanation here Unicode Controls for Bidirectional Text to better understand how the change of direction override characters work.
CodeBlender's answer points you to an example that works fine – however, be careful when saving file names that contain extended charsets, as you may encounter issues when saving to legacy operating systems, or when transferring between computers, for example.