1.說明:From:從指定位置到結尾。To:從開頭到指定位置。WithRange:傳回一個範圍和NSRange並用
- (NSString *)substringFromIndex:(NSUInteger)from; - (NSString *)substringToIndex:(NSUInteger)to; - (NSString *)substringWithRange:(NSRange)range;//Hint: Use with rangeOfComposedCharacterSequencesForRange: to avoid breaking up composed characters
<以下範例>
NSString *string1 = @"this blog is n11 studio"; NSString *string2 = [string1 substringFromIndex:13]; NSLog(@"%@",string2); //the answer is "n11 studio"
2.說明:Pre:判斷接收訊息的物件開頭是否為aString。Suf:判斷結尾是否是aString
- (BOOL)hasPrefix:(NSString *)aString; - (BOOL)hasSuffix:(NSString *)aString;
沒有留言:
張貼留言