Substrings from NSString AasimNaseem, March 13, 2012April 9, 2025 Hello iOS geeks … Here is a small tip for getting a substring from NSString; NSString class provide following methods for splitting a string; [sourcecode lang=”objc”] – (NSString *)substringFromIndex:(NSUInteger)from; – (NSString *)substringToIndex:(NSUInteger)to; – (NSString *)substringWithRange:(NSRange)range; – (NSRange)rangeOfString:(NSString *)<em>aString;</em> [/sourcecode] Following code will demonstrate itself; [sourcecode lang=”objc”] NSString testString = @”I love programming in objective-c”; [testString substringToIndex:5]; // will return I Love [testString substringFromIndex:7]; // will return pogramming in objective-c [testString substringWithRange:NSMakeRange(21, 32)]; // will return objective-c Use this method to check whether the giving string present in the target string or not. [testString rangeOfString:@”love”]; // Will return an NSRange structure giving the location and length in the receiver of the first occurrence of aString. Returns ]{NSNotFound, 0} if =aString is not found or is empty (@””). [/sourcecode] I think self descriptive code chunk, so no need to write anything more; (: Happy Development; This post belongs to N-FAQ category where i post anything i learn new (no matter how its small or big) during my work; N-FAQ = Not-FAQ; iOS how to get substring from nsstringhow to split string iosiosNSRangeMakeNSStrngsubstring of nsstringsubstringFromIndexsubstringToIndexsubstringWithRange