Usman Javed
Usman Javed

Reputation: 2455

Objective-C: Best way to delete substring from NSString?

If I want to delete a value from the NSString @"this is my book", what should I use?

The return value I want is @"this is book".

Upvotes: 1

Views: 6108

Answers (2)

Christian
Christian

Reputation: 382

You can use NSRange

    NSString *string = @"lorem ipsum dolor sit amet";

NSRange range = [string rangeOfString:@"ipsum"]; // {.location=6, .length=5}

NSString *substring = [string substringWithRange:

Upvotes: -2

Mrunal
Mrunal

Reputation: 14118

NSString *myString = @"this is my book";

myString  = [myString stringByReplacingOccurrencesOfString:@" my " withString:@" "];

Hope this helps

Upvotes: 9

Related Questions