Monday, May 20, 2013

NSString substringFromIndex example ios


[NSString substringFromIndex]

Returns a new string containing the characters of the receiver from the one at a given index to the end.
- (NSString *)substringFromIndex:(NSUInteger)anIndex
Parameters
anIndex
An index. The value must lie within the bounds of the receiver, or be equal to the length of the receiver.

Important: Raises an NSRangeException if anIndex lies beyond the end of the receiver.
Return Value of [NSString substringFromIndex]
A new string containing the characters of the receiver from the one at anIndex to the end. If anIndex is equal to the length of the string, returns an empty string.
Example of [NSString substringFromIndex]
NSString *str = @"A. rahul VyAs";
NSString *newStr = [str substringFromIndex:3];
Example of [NSString substringFromIndex]
NSString *newString;
if ( [[myString characterAtIndex:0] isEqualToString:@"*"] ) {
     newString = [myString substringFromIndex:1];
}
Example of [NSString substringFromIndex]
NSMutableString *myString = [[NSMutableString alloc] initWithString:@"This is my String"];
NSString *tmpString = [myString substringFromIndex:5];
NSLog(@"tempStr = %@", tempString);
[myString setString:tempStr];

// later do [myString release]