SirRatty
SirRatty

Reputation: 2406

Cocoa - Remove All Chars Before and Including Substring from String

getting myself confused with NSString's various range methods and where and when they should be used.

I have a random string. Somewhere in the string it may (or may not) contain an identifier such as "Customer Name:" (the quotes will not be included.)

Problem: I need a new string where everything up to and including "Customer Name:" has been removed from the original string.

Any advice is appreciated.

Mac OS X 10.4 compatibility required, manual GC.

Upvotes: 0

Views: 324

Answers (1)

Wevah
Wevah

Reputation: 28242

NSRange range = [str rangeOfString:@"Customer Name:"];
NSString *newStr = [str substringFromIndex:range.location + range.length];

Upvotes: 3

Related Questions