Important: The information in this document is obsolete and should not be used for new development.
Inherits from | Object |
Implements |
Cloneable |
Package | com.apple.cocoa.foundation |
Companion guide | Geometry and Range Utilities |
An NSRange represents a range, a measurement of a segment of something linear, such as a byte stream. An NSRange has two primary values, a location and a length. The methods of NSRange give access to these values; convert between NSRanges and their string representations; test and compare ranges; and create ranges based on operations involving the union, intersection, and subtraction of two ranges.
public NSRange
()
Returns an empty NSRange.
public NSRange
(int location, int length)
Initializes the NSRange with the range elements of location and length; it throws an IllegalArgumentException
if either integer is negative.
public NSRange
(NSRange aRange)
Initializes the new NSRange with the location and length values of aRange; this constructor is used in cloning the receiver.
public static NSRange fromString
(String rangeAsString)
Creates an NSRange from the string rangeAsString, which must be of the form “{loc, len}” where loc is a number representing the starting location of the range and len is the range’s length. Throws an IllegalArgumentException
if the string is improperly formatted.
Creates and returns a copy of the receiver.
public Object clone
()
Returns whether otherObject is an NSRange and is equal in location and length to the receiver.
public boolean equals
(Object otherObject)
Provides an appropriate hash code useful for storing the receiver in a hash-based data structure.
public int hashCode
()
This value is the sum of the receiver’s location and length.
Returns whether the range aRange intersects the receiver.
public boolean intersectsRange
(NSRange aRange)
Returns whether the length of the receiver is 0.
public boolean isEmpty
()
Returns whether the range aRange is equal in both location and length to the receiver.
public boolean isEqualToRange
(NSRange aRange)
Returns whether the receiver’s endpoints match or fall within those of range aRange.
public boolean isSubrangeOfRange
(NSRange aRange)
Returns the length of the receiver from its starting location.
public int length
()
Returns the starting location of the receiver.
public int location
()
Returns whether the location aLocation comes after or matches the starting location and comes before the ending location of the receiver.
public boolean locationInRange
(int aLocation)
Returns the extent of the receiver (its starting location plus its length).
public int maxRange
()
This number is 1 greater than the last location in the range.
Returns an NSRange that is the intersection of aRange and the receiver.
public NSRange rangeByIntersectingRange
(NSRange aRange)
If the ranges do not intersect, returns an empty range (see isEmpty
).
Returns an NSRange that is the union of aRange and the receiver (a range constructed from the lowest starting location and the highest ending location of both NSRanges).
public NSRange rangeByUnioningRange
(NSRange aRange)
Returns the ranges resulting from the subtraction of otherRange from the receiver by modifying the mutable ranges resultRange1 and resultRange2 (provided by the caller).
public void subtractRange
(NSRange otherRange, NSMutableRange resultRange1, NSMutableRange resultRange2)
Either or both of the result ranges might be empty when this method returns.
Returns a String representing the receiver’s starting location and length.
public String toString
()
The string has the form “{loc, len}”, where loc is the starting location of the range and len is its length.
NSRange provides the following constant as a convenience; you can use it to compare values returned by some NSRange methods:
© 1997, 2006 Apple Computer, Inc. All Rights Reserved. (Last updated: 2006-07-24)