1

I have an NSString like this @"uE604" that I want to add a backslash too in order to use it as a unicode character. However I am having issues trying to get that to work. If I add @"\\" to the front of it, it doesn't work.

Any way I can get it working?

2 Answers 2

1

Try using just one slash: @"\uE604".

Sign up to request clarification or add additional context in comments.

7 Comments

how would I concatenate that string to @"\"?
The sequence \uXXXX is a unicode string literal. The hex sequence is decoded at compile-time and the actual unicode symbol is inserted in its place. Is this when you want to put the character in, or do you want to do it with some arbitrary hex string at runtime?
If you want a backlash in front of a unicode character at compile-time, you would do @"\\\uE604".
Okay, so I would have to try and convert the initial text into a hex string and then concatenate that to 5c, then do another conversion into the unicode character?
If you want to do it at runtime, yes. First convert the hex string to an integer (see stackoverflow.com/a/3648562/312594), then initialize an NSString with its value (see stackoverflow.com/a/30817609/312594).
|
0

Just use one slash, since you are working with Unicode you don't need to escape the slash:

NSString *s = @"\u266A";

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.