[Previous]
[Up]
[Next]
NSString
Authors
- Richard Frith-Macdonald
-
- James Dessart
-
Version: $Revision$
Date: $Date$
Declared in: Foundation/NSString.h
Inherits from: NSObject
Conforms to: NSCoding
NSString objects represent an immutable string of characters.
NSString itself is an abstract class which provides factory
methods to generate objects of unspecified subclasses.
A constant NSString can be created using the following syntax:
@"..."
, where the contents of the quotes are the
string, using only ASCII characters.
To create a concrete subclass of NSString, you must have your
class inherit from NSString and override at least the two
primitive methods - length and characterAtIndex:
In general the rule is that your subclass must override any
initialiser that you want to use with it. The GNUstep
implementation relaxes that to say that, you may override
only the designated initialiser and the other
initialisation methods should work.
Instance Variables
Methods
Class Methods
+ (const NSStringEncoding*) availableStringEncodings;
Returns an array of all available string encodings,
terminated by a null value.
+ (NSStringEncoding) defaultCStringEncoding;
Returns the encoding used for any method accepting a C string.
This value is determined automatically from the programs
environment and cannot be changed programmatically.
You should NOT override this method in an attempt to
change the encoding being used.
In GNUstep, this encoding is determined by the initial value
of the GNUSTEP_STRING_ENCODING
environment
variable. If this is not defined,
NSISOLatin1StringEncoding
is assumed.
The default C string encoding must be a characterset containing
7 or 8 bit characters, and where the characters are a superset
of the 7-bit ASCII characterset. In particular, this means
that NSUTF8StringEncoding and NSUnicodeStringEncoding are not
permissable.
+ (NSString*) localizedNameOfStringEncoding: (NSStringEncoding)encoding;
Returns the localized name of the encoding specified
by encoding.
+ (NSString*) localizedStringWithFormat: (NSString*)format,;
+ (NSString*) pathWithComponents: (NSArray*)components;
+ (id) string;
+ (id) stringWithCharacters: (const unichar*)chars length: (unsigned int)length;
+ (id) stringWithContentsOfFile: (NSString*)path;
+ (id) stringWithCString: (const char*)cString;
+ (id) stringWithCString: (const char*)cString;
+ (id) stringWithFormat: (NSString*)format,;
+ (id) stringWithString: (NSString*)aString;
+ (void) getLineStart: (unsigned int*)startIndex end: (unsigned int*)lineEndIndex contentsEnd: (unsigned int*)contentsEndIndex;
+ (NSRange) lineRangeForRange: (NSRange)aRange;
Instances Methods
- (BOOL) canBeConvertedToEncoding: (NSStringEncoding)encoding;
- (NSString*) capitalizedString;
- (NSComparisonResult) caseInsensitiveCompare: (NSString*)aString;
- (unichar) characterAtIndex: (unsigned int)index;
- (NSString*) commonPrefixWithString: (NSString*)aString;
- (NSComparisonResult) compare: (NSString*)aString;
- (NSComparisonResult) compare: (NSString*)aString;
- (NSComparisonResult) compare: (NSString*)aString options: (unsigned int)mask range: (NSRange)aRange;
- (unsigned int) completePathIntoString: (NSString**)outputName caseSensitive: (BOOL)flag matchesIntoArray: (NSArray**)outputArray;
- (NSArray*) componentsSeparatedByString: (NSString*)separator;
- (const char*) cString;
Returns a pointer to a nul terminated string of 8-bit
characters in the default encoding. The memory pointed
to is not owned by the caller, so the caller must copy
its contents to keep it.
- (unsigned int) cStringLength;
- (NSData*) dataUsingEncoding: (NSStringEncoding)encoding;
- (NSData*) dataUsingEncoding: (NSStringEncoding)encoding allowLossyConversion: (BOOL)flag;
- (NSString*) description;
- (double) doubleValue;
- (NSStringEncoding) fastestEncoding;
- (const char*) fileSystemRepresentation;
- (float) floatValue;
- (void) getCharacters: (unichar*)buffer;
- (void) getCharacters: (unichar*)buffer;
- (void) getCString: (char*)buffer;
- (void) getCString: (char*)buffer maxLength: (unsigned int)maxLength;
- (void) getCString: (char*)buffer maxLength: (unsigned int)maxLength range: (NSRange)aRange remainingRange: (NSRange*)leftoverRange;
- (BOOL) getFileSystemRepresentation: (char*)buffer maxLength: (unsigned int)maxLength;
- (unsigned int) hash;
- (BOOL) hasPrefix: (NSString*)aString;
- (BOOL) hasSuffix: (NSString*)aString;
- (id) init;
- (id) initWithCharacters: (const unichar*)characters;
This is the designated initialiser
- (id) initWithCharactersNoCopy: (unichar*)characters length: (unsigned int)length freeWhenDone: (BOOL)flag;
This is the most basic initialiser for unicode strings.
In the GNUstep implementation, your subclasses may override
this initialiser in order to have all others function.
- (id) initWithContentsOfFile: (NSString*)path;
- (id) initWithCString: (const char*)cString;
- (id) initWithCString: (const char*)cString;
- (id) initWithCStringNoCopy: (char*)cString length: (unsigned int)length freeWhenDone: (BOOL)flag;
- (id) initWithData: (NSData*)data encoding: (NSStringEncoding)encoding;
- (id) initWithFormat: (NSString*)format, ...;
Invokes initWithFormat:locale:arguments with a nil locale.
- (id) initWithFormat: (NSString*)format arguments: (va_list)argList;
Invokes initWithFormat:locale:arguments with a nil locale.
- (id) initWithFormat: (NSString*)format locale: (NSDictionary*)dictionary, ...;
Initialises the string using the specified format and local
to format the following arguments.
- (id) initWithFormat: (NSString*)format arguments: (va_list)argList;
Invokes initWithFormat:locale:,... with a nil locale.
- (id) initWithFormat: (NSString*)format locale: (NSDictionary*)dictionary arguments: (va_list)argList;
Initialises the string using the specified format and local
to format the following arguments.
- (id) initWithString: (NSString*)aString;
- (int) intValue;
- (BOOL) isAbsolutePath;
- (BOOL) isEqualToString: (NSString*)aString;
- (NSString*) lastPathComponent;
- (unsigned int) length;
- (const char*) lossyCString;
- (NSString*) lowercaseString;
Returns a copy of the receiver with all characters converted
to lowercase.
- (NSArray*) pathComponents;
- (NSString*) pathExtension;
- (id) propertyList;
- (NSDictionary*) propertyListFromStringsFileFormat;
- (NSRange) rangeOfCharacterFromSet: (NSCharacterSet*)aSet;
- (NSRange) rangeOfCharacterFromSet: (NSCharacterSet*)aSet options: (unsigned int)mask;
- (NSRange) rangeOfCharacterFromSet: (NSCharacterSet*)aSet options: (unsigned int)mask range: (NSRange)aRange;
- (NSRange) rangeOfComposedCharacterSequenceAtIndex: (unsigned int)anIndex;
- (NSRange) rangeOfString: (NSString*)aString;
Invokes rangeOfString:options: with the options mask
set to zero.
- (NSRange) rangeOfString: (NSString*)aString options: (unsigned int)mask;
Invokes rangeOfString:options:range with the range set
set to the range of the whole of the reciever.
- (NSRange) rangeOfString: (NSString*)subString options: (unsigned int)mask range: (NSRange)aRange;
Returns the range giving the location and length of the first
occurrence of subString within aRange.
If subString does not exist in the receiver (an empty
string is never considered to exist in the receiver),
the length of the returned range is zero.
If substring is nil, an exception is raised.
If any part of aRange lies outside the range of the
receiver, an exception is raised.
The optionsm mask may contain the following options -
- NSCaseInsensitiveSearch
- NSLiteralSearch
- NSBackwardsSearch
- NSAnchoredSearch
- (NSStringEncoding) smallestEncoding;
- (NSString*) stringByAbbreviatingWithTildeInPath;
- (NSString*) stringByAppendingFormat: (NSString*)format,;
- (NSString*) stringByAppendingPathComponent: (NSString*)aString;
- (NSString*) stringByAppendingPathExtension: (NSString*)string;
- (NSString*) stringByAppendingString: (NSString*)aString;
- (NSString*) stringByDeletingLastPathComponent;
- (NSString*) stringByDeletingPathExtension;
- (NSString*) stringByExpandingTildeInPath;
- (NSString*) stringByReplacingString: (NSString*)aString withString: (NSString*)replacement;
Standards: GNUstep NotMacOS-X NotOpenStep
Returns a string in which any (and all) occurrances of
aString in the receiver have been replaced by
replacement. Returns the receiver if aString
does not occur within the receiver. NB. an empty string is
not considered to exist within the receiver.
- (NSArray*) stringsByAppendingPaths: (NSArray*)paths;
- (NSString*) substringFromIndex: (unsigned int)anIndex;
- (NSString*) substringToIndex: (unsigned int)anIndex;
- (NSString*) substringWithRange: (NSRange)aRange;
- (NSString*) uppercaseString;
Returns a copy of the receiver with all characters converted
to uppercase.
- (BOOL) writeToFile: (NSString*)path atomically: (BOOL)flag;