RomanHouse
RomanHouse

Reputation: 2552

How to delete NSString's text from another NSString

For example:

NSString *sentence = @"My name is Roman";
NSString *name  = @"Roman";

Is there way to delete name's text from sentence string?

Upvotes: 0

Views: 148

Answers (3)

Imirak
Imirak

Reputation: 1333

Alternatively, you can use substringWithRange: like so:

NSString *finalString = [sentence substringWithRange:NSMakeRange(3, 16)];

Upvotes: 1

Gabriel
Gabriel

Reputation: 3359

Yes

sentence = [sentence stringByReplacingOccurrencesOfString:name withString:@""];

Upvotes: 8

Matt Wilding
Matt Wilding

Reputation: 20163

NSString* result = [sentence stringByReplacingOccurrencesOfString:name withString:@""];

Upvotes: 10

Related Questions