0

I'm trying to save an UTF8 char to a string and print it to a label.

If I hard code it works fine:

NSString *param = @"\uf02e";
NSLog(param);

Result:

2012-10-24 16:09:56.522 i[22996:12c03] 

By the way if I'm saving the char to a string I can't go back.

NSString *myString = [NSString stringWithFormat:@"%@",[item objectForKey:content]];
NSLog(myString);

Result:

2012-10-24 16:18:47.289 i[23105:12c03] \uf02e

Any solution for this? Thanks.

EDIT

item is an NSDictionary and [item objectForKey:content] is a string.

enter image description here

3
  • How do you fill [item] array? Commented Oct 24, 2012 at 14:24
  • item is an NSDictionary filled with objects from a plist file. Commented Oct 24, 2012 at 14:41
  • So in your plist string is actually the string "\uf02e" itself, not the corresponding unicode character. Modifier \u doesn't work inside of strings inside of plist. Commented Oct 25, 2012 at 15:25

1 Answer 1

1
    NSString *param = @"\uf02e";
    NSDictionary* item = [NSDictionary dictionaryWithObject: param forKey: @"key"];
    NSString *myString = [NSString stringWithFormat:@"%@",[item objectForKey: @"key"]];
    NSLog(myString);

Works fine for me. So the error is in the value, that you're inserting into the dictionary.

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

9 Comments

I have attached an image. The value is saved correctly on the plist file as String. Your solution works but not with my code.
how do you load it from plist ?
+1 @CarloS The value you have stored in the dictionary looks like the string "\uf02e" (i.e. the escape sequence you'd supply to the compiler). This won't work when the string is loaded like this as the compiler won't interpret the escape characters this way. In fact the compiler won't see the string at all, will it.
It's quite complex to paste all the code. By the way myString is a string, same as param. Can't understand why they are treated differently.
Any way to convert "\uf02e" to \uf02e ? Cause I can't change the way I'm filling the dictionary.
|

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.