开发者

Cocoa - Remove All Chars Before and Including Substring from String

开发者 https://www.devze.com 2023-01-05 22:14 出处:网络
getting myself confused with NSString\'s various range metho开发者_如何学编程ds and where and when they should be used.

getting myself confused with NSString's various range metho开发者_如何学编程ds 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.


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

精彩评论

暂无评论...
验证码 换一张
取 消