Manann Sseth
Manann Sseth

Reputation: 2745

Character replacing in Xcode - Objective-C

I have used this code for replacing "\n" with "", but it is not working.

How can I do it?

NSString *descString = [values objectForKey:@"description"];
descString = [descString stringByReplacingOccurrencesOfString:@"\n" withString:@""];

NSLog(@"Description String ---->>> %@",descString);
catlog.description = descString;
[webview loadHTMLString:catlog.description baseURL:nil];
webview.opaque = NO;

Upvotes: 2

Views: 13030

Answers (2)

KDeogharkar
KDeogharkar

Reputation: 10959

descString = [descString stringByReplacingOccurrencesOfString:@"\\n" withString:@""];

For more information refer to stringByReplacingOccurrencesOfString:withString: method

Hope this helps you.

UPDATE

Swift 3.0

descString.replacingOccurrences(of: "\\n", with: "");

and If I am not wring it will also work for Swift 4.0

Upvotes: 5

Heer Makwana
Heer Makwana

Reputation: 905

try this

NSString *s = @"foo/bar:baz.foo";
NSCharacterSet *doNotWant = [NSCharacterSet characterSetWithCharactersInString:@"/:."];
s = [[s componentsSeparatedByCharactersInSet: doNotWant] componentsJoinedByString: @""];
NSLog(@"%@", s);

Upvotes: 10

Related Questions