remove "\n" from NSString

nsstring, objective-c

Solution

Try it :

NSString *address = @"129 City Road \nShoreditch \nLondon EC1V 1JB";    
address = [address stringByReplacingOccurrencesOfString:@"\n" withString:@""];
address = [address stringByTrimmingCharactersInSet:[NSCharacterSet newlineCharacterSet]];

This worked and i got the output like :

129 City Road Shoreditch London EC1V 1JB

Problem

My json is returning this : address = "129 City Road \nShoreditch \nLondon EC1V 1JB"; I want to remove the "\n". Because I want to display it in one line. I tried following: ``` NSString * newReplacedString = [string stringByReplacingOccurrencesOfString:@"\n" withString:@""]; NSString * newReplacedString = [string stringByTrimmingCharactersInSet:[NSCharacterSet newlineCharacterSet]]; ``` Both result same: Result 900 N Michigan Avenue Chicago Illinois 60611 If I tried this ``` NSString *s = [string stringByReplacingOccurrencesOfString:@"\n" withString:@"\\n"]; ``` Result 900 N Michigan Avenue \nChicago \nIllinois 60611 Please suggest.

Original source

Related problems