I work often with json.
Json is a text-based open standard designed for human-readable data interchange. It is derived from the JavaScript scripting language for representing simple data structures and associative arrays, called objects. Despite its relationship to JavaScript, it is language-independent, with parsers available for many languages. For more information about this standard refer to RFC 4627.
There are several parser I can use when I'm developing applications for the iPhone using Objective-C, one of the problems I had, was the presence, into the results, of the "\n" characters to divide one line from another.
To remove "\n" characters within a NSString you can use the methods of the NSString class, there are several ways to do this, the way I use is the following one:
I create a new string from the original using the stringByReplacingOccurrencesOfString method.
The following piece of code will do the work:
void myMethod(void)
{
NSString *originalString = @"\nTitle Book\nAuthor\npages";
NSLog(@"%@", originalString);
NSString *finalString;
finalString = [originalString stringByReplacingOccurrencesOfString:@"\n" withString:@""];
NSLog(@"%@", finalString);
}
The first NSLog statement will produce the following output:
2013-01-13 17:21:02.046 testperxapp[2441:c07]
Title Book
Author
pages
While the last NSLog statement will produce the following output:
2013-01-13 17:21:02.048 testperxapp[2441:c07] Title BookAuthorpages
And that's all,
Gg1
Why not use [myString stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];?
@Arthur Mayes this method removes only the characters at the beginning and at the end of string.