Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swift String literal for unicode character is wrong

I am trying to pass a unicode character from Swift to a UIWebPage. The String is coming in from the server as "\\2020" so that the escaped version should be "\2020" (the dagger symbol). When it is passed in however, it is becoming "2020". Is it breaking in the javascript or before it gets there?

like image 749
Lee Probert Avatar asked May 09 '16 09:05

Lee Probert


People also ask

What is Unicode string literal?

If the character string literal has a prefix of N, the literal is treated as a Unicode string. When the N prefix is used, the characters in the literal are read as WCHAR characters. Any string literal with non-ASCII characters is treated as a Unicode literal by default.

Does string support Unicode?

@MSalters: std::string can hold 100% of all Unicode characters, even if CHAR_BIT is 8. It depends on the encoding of std::string, which may be UTF-8 on the system level (like almost everywhere except for windows) or on your application level.

How do you escape special characters in Swift?

Swift's escape character is \ , the backslash (U+005C). Escape character sequences (shortened to escape sequence) represent special characters. In the current version of Swift, the backslash escape character tells the compiler that a sequence should combine to produce one of these special characters.

How do you check if a string contains a character in Swift?

In the Swift string, we check if the specified string is present in a string or not. To do this task we use the contains() function. This function is used to check whether the specified string i.e. sequence of characters is present in the string or not.


1 Answers

To represent the character in Swift you must use this kind of interpolation:

let dagger = "\u{2020}"
like image 143
Eric Aya Avatar answered Oct 13 '22 22:10

Eric Aya