[Previous] [Up] [Next]

NSString

Authors

Richard Frith-Macdonald
James Dessart

Version: $Revision$

Date: $Date$

NSString

NSString

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

availableStringEncodings

+ (const NSStringEncoding*) availableStringEncodings;

Returns an array of all available string encodings, terminated by a null value.


defaultCStringEncoding

+ (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.


localizedNameOfStringEncoding:

+ (NSString*) localizedNameOfStringEncoding: (NSStringEncoding)encoding;

Returns the localized name of the encoding specified by encoding.


localizedStringWithFormat:

+ (NSString*) localizedStringWithFormat: (NSString*)format,;

pathWithComponents:

+ (NSString*) pathWithComponents: (NSArray*)components;

string

+ (id) string;

stringWithCharacters:length:

+ (id) stringWithCharacters: (const unichar*)chars length: (unsigned int)length;

stringWithContentsOfFile:

+ (id) stringWithContentsOfFile: (NSString*)path;

stringWithCString:

+ (id) stringWithCString: (const char*)cString;

stringWithCString:

+ (id) stringWithCString: (const char*)cString;

stringWithFormat:

+ (id) stringWithFormat: (NSString*)format,;

stringWithString:

+ (id) stringWithString: (NSString*)aString;

getLineStart:end:contentsEnd:

+ (void) getLineStart: (unsigned int*)startIndex end: (unsigned int*)lineEndIndex contentsEnd: (unsigned int*)contentsEndIndex;

lineRangeForRange:

+ (NSRange) lineRangeForRange: (NSRange)aRange;


Instances Methods

canBeConvertedToEncoding:

- (BOOL) canBeConvertedToEncoding: (NSStringEncoding)encoding;

capitalizedString

- (NSString*) capitalizedString;

caseInsensitiveCompare:

- (NSComparisonResult) caseInsensitiveCompare: (NSString*)aString;

characterAtIndex:

- (unichar) characterAtIndex: (unsigned int)index;

commonPrefixWithString:

- (NSString*) commonPrefixWithString: (NSString*)aString;

compare:

- (NSComparisonResult) compare: (NSString*)aString;

compare:

- (NSComparisonResult) compare: (NSString*)aString;

compare:options:range:

- (NSComparisonResult) compare: (NSString*)aString options: (unsigned int)mask range: (NSRange)aRange;

completePathIntoString:caseSensitive:matchesIntoArray:

- (unsigned int) completePathIntoString: (NSString**)outputName caseSensitive: (BOOL)flag matchesIntoArray: (NSArray**)outputArray;

componentsSeparatedByString:

- (NSArray*) componentsSeparatedByString: (NSString*)separator;

cString

- (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.

cStringLength

- (unsigned int) cStringLength;

dataUsingEncoding:

- (NSData*) dataUsingEncoding: (NSStringEncoding)encoding;

dataUsingEncoding:allowLossyConversion:

- (NSData*) dataUsingEncoding: (NSStringEncoding)encoding allowLossyConversion: (BOOL)flag;

description

- (NSString*) description;

doubleValue

- (double) doubleValue;

fastestEncoding

- (NSStringEncoding) fastestEncoding;

fileSystemRepresentation

- (const char*) fileSystemRepresentation;

floatValue

- (float) floatValue;

getCharacters:

- (void) getCharacters: (unichar*)buffer;

getCharacters:

- (void) getCharacters: (unichar*)buffer;

getCString:

- (void) getCString: (char*)buffer;

getCString:maxLength:

- (void) getCString: (char*)buffer maxLength: (unsigned int)maxLength;

getCString:maxLength:range:remainingRange:

- (void) getCString: (char*)buffer maxLength: (unsigned int)maxLength range: (NSRange)aRange remainingRange: (NSRange*)leftoverRange;

getFileSystemRepresentation:maxLength:

- (BOOL) getFileSystemRepresentation: (char*)buffer maxLength: (unsigned int)maxLength;

hash

- (unsigned int) hash;

hasPrefix:

- (BOOL) hasPrefix: (NSString*)aString;

hasSuffix:

- (BOOL) hasSuffix: (NSString*)aString;

init

- (id) init;

initWithCharacters:

- (id) initWithCharacters: (const unichar*)characters;

initWithCharactersNoCopy:length:freeWhenDone:

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.

initWithContentsOfFile:

- (id) initWithContentsOfFile: (NSString*)path;

initWithCString:

- (id) initWithCString: (const char*)cString;

initWithCString:

- (id) initWithCString: (const char*)cString;

initWithCStringNoCopy:length:freeWhenDone:

- (id) initWithCStringNoCopy: (char*)cString length: (unsigned int)length freeWhenDone: (BOOL)flag;

initWithData:encoding:

- (id) initWithData: (NSData*)data encoding: (NSStringEncoding)encoding;

initWithFormat:

- (id) initWithFormat: (NSString*)format, ...;
Invokes initWithFormat:locale:arguments with a nil locale.

initWithFormat:arguments:

- (id) initWithFormat: (NSString*)format arguments: (va_list)argList;
Invokes initWithFormat:locale:arguments with a nil locale.

initWithFormat:locale:

- (id) initWithFormat: (NSString*)format locale: (NSDictionary*)dictionary, ...;
Initialises the string using the specified format and local to format the following arguments.

initWithFormat:arguments:

- (id) initWithFormat: (NSString*)format arguments: (va_list)argList;
Invokes initWithFormat:locale:,... with a nil locale.

initWithFormat:locale:arguments:

- (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.

initWithString:

- (id) initWithString: (NSString*)aString;

intValue

- (int) intValue;

isAbsolutePath

- (BOOL) isAbsolutePath;

isEqualToString:

- (BOOL) isEqualToString: (NSString*)aString;

lastPathComponent

- (NSString*) lastPathComponent;

length

- (unsigned int) length;

lossyCString

- (const char*) lossyCString;

lowercaseString

- (NSString*) lowercaseString;
Returns a copy of the receiver with all characters converted to lowercase.

pathComponents

- (NSArray*) pathComponents;

pathExtension

- (NSString*) pathExtension;

propertyList

- (id) propertyList;

propertyListFromStringsFileFormat

- (NSDictionary*) propertyListFromStringsFileFormat;

rangeOfCharacterFromSet:

- (NSRange) rangeOfCharacterFromSet: (NSCharacterSet*)aSet;

rangeOfCharacterFromSet:options:

- (NSRange) rangeOfCharacterFromSet: (NSCharacterSet*)aSet options: (unsigned int)mask;

rangeOfCharacterFromSet:options:range:

- (NSRange) rangeOfCharacterFromSet: (NSCharacterSet*)aSet options: (unsigned int)mask range: (NSRange)aRange;

rangeOfComposedCharacterSequenceAtIndex:

- (NSRange) rangeOfComposedCharacterSequenceAtIndex: (unsigned int)anIndex;

rangeOfString:

- (NSRange) rangeOfString: (NSString*)aString;
Invokes rangeOfString:options: with the options mask set to zero.

rangeOfString:options:

- (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.

rangeOfString:options:range:

- (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 -

smallestEncoding

- (NSStringEncoding) smallestEncoding;

stringByAbbreviatingWithTildeInPath

- (NSString*) stringByAbbreviatingWithTildeInPath;

stringByAppendingFormat:

- (NSString*) stringByAppendingFormat: (NSString*)format,;

stringByAppendingPathComponent:

- (NSString*) stringByAppendingPathComponent: (NSString*)aString;

stringByAppendingPathExtension:

- (NSString*) stringByAppendingPathExtension: (NSString*)string;

stringByAppendingString:

- (NSString*) stringByAppendingString: (NSString*)aString;

stringByDeletingLastPathComponent

- (NSString*) stringByDeletingLastPathComponent;

stringByDeletingPathExtension

- (NSString*) stringByDeletingPathExtension;

stringByExpandingTildeInPath

- (NSString*) stringByExpandingTildeInPath;

stringByReplacingString:withString:

- (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.

stringsByAppendingPaths:

- (NSArray*) stringsByAppendingPaths: (NSArray*)paths;

substringFromIndex:

- (NSString*) substringFromIndex: (unsigned int)anIndex;

substringToIndex:

- (NSString*) substringToIndex: (unsigned int)anIndex;

substringWithRange:

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

uppercaseString

- (NSString*) uppercaseString;
Returns a copy of the receiver with all characters converted to uppercase.

writeToFile:atomically:

- (BOOL) writeToFile: (NSString*)path atomically: (BOOL)flag;