wwjdm
wwjdm

Reputation: 2596

ios: Replace word in NSString with a return

I have the following NSString:

"This is a test String
*This a test string"

I want to replace the "*" with a return like so

"This is a test string

This is a test string"

I tried:

[removeStr stringByReplacingOccurrencesOfString:@"*" withString:@"/r"];

but it prints "/r" and when I try "\r" I get an lldb error

Any help?

Upvotes: 0

Views: 980

Answers (1)

kyktommy
kyktommy

Reputation: 36

NSString *str = @"This is a test String*This a test string";
NSString *str2 = [str stringByReplacingOccurrencesOfString:@"*" withString:@"\n"];
NSLog(@"%@", str2);

If the string like that, replace \n, then the result is:

This is a test String
This a test string

Upvotes: 2

Related Questions