Instance Method

substringWithRange:

Returns a string object containing the characters of the receiver that lie within a given range.

Declaration

- (NSString *)substringWithRange:(NSRange)range;

Parameters

aRange

A range. The range must not exceed the bounds of the receiver.

Raises an NSRangeException if (aRange.location - 1) or (aRange.location + aRange.length - 1) lies beyond the end of the receiver.

Return Value

A string object containing the characters of the receiver that lie within aRange.

Discussion

This method detects all invalid ranges (including those with negative lengths). For applications linked against macOS 10.6 and later, this error causes an exception; for applications linked against earlier releases, this error causes a warning, which is displayed just once per application execution.

See Also

Dividing Strings

componentsSeparatedByString:

Returns an array containing substrings from the receiver that have been divided by a given separator.

componentsSeparatedByCharactersInSet:

Returns an array containing substrings from the receiver that have been divided by characters in a given set.

stringByTrimmingCharactersInSet:

Returns a new string made by removing from both ends of the receiver characters contained in a given character set.

substringFromIndex:

Returns a new string containing the characters of the receiver from the one at a given index to the end.

substringToIndex:

Returns a new string containing the characters of the receiver up to, but not including, the one at a given index.