0

I have a NSDictionary with the following values

"key1" = "abc\ndef"
"key2" = "1234568"

Get value from dictionary

NSString *myString = [myDictionary objectForKey:@"key1"];

If I output "myString" in the debugger I get

abc
def

So how do I get the value from the dictionary so that "myString" will output

abc\ndef

just like it is in the dictionary?

Thanks!

4

1 回答 1

0

Before output in debugger you can escape newline characters:

NSString *myString = [[myDictionary objectForKey:@"key1"] stringByReplacingOccurrencesOfString:@"\n" withString:@"\\n"];

It will be printed with "\n".

于 2013-10-29T21:13:43.437 回答