Class: NSString

Inherits:
NSObject show all

Overview

The NSString class declares the programmatic interface for an object that manages immutable strings. An immutable string is a text string that is defined when it is created and subsequently cannot be changed. NSString is implemented to represent an array of Unicode characters, in other words, a text string.

Direct Known Subclasses

NSMutableString, Symbol

Class Method Summary (collapse)

Instance Method Summary (collapse)

Methods inherited from NSObject

#!, #!=, #!~, #, #==, #===, #=~, #Rational, #__callee__, #__method__, #__send__, #__type__, `, alloc, allocWithZone:, #autoContentAccessingProxy, autoload, autoload?, autorelease_pool, #awakeAfterUsingCoder:, binding, block_given?, caller, cancelPreviousPerformRequestsWithTarget:, cancelPreviousPerformRequestsWithTarget:selector:object:, catch, class, classFallbacksForKeyedArchiver, #classForCoder, #classForKeyedArchiver, classForKeyedUnarchiver, #clone, conformsToProtocol:, #copy, copyWithZone:, #dealloc, #define_singleton_method, description, display, #doesNotRecognizeSelector:, #dup, #enum_for, #eql?, #equal?, #extend, fail, #finalize, format, #forwardInvocation:, #forwardingTargetForSelector:, framework, #freeze, #frozen?, getpass, gets, global_variables, #init, initialize, #initialize_clone, #initialize_copy, #initialize_dup, #inspect, instanceMethodForSelector:, instanceMethodSignatureForSelector:, #instance_eval, #instance_exec, #instance_of?, #instance_variable_defined?, #instance_variable_get, #instance_variable_set, #instance_variables, instancesRespondToSelector:, isSubclassOfClass:, #is_a?, iterator?, #kind_of?, lambda, load, load_bridge_support_file, load_plist, local_variables, loop, #method, #methodForSelector:, #methodSignatureForSelector:, #methods, #mutableCopy, mutableCopyWithZone:, new, #nil?, open, p, #performSelector:onThread:withObject:waitUntilDone:, #performSelector:onThread:withObject:waitUntilDone:modes:, #performSelector:withObject:afterDelay:, #performSelector:withObject:afterDelay:inModes:, #performSelectorInBackground:withObject:, #performSelectorOnMainThread:withObject:waitUntilDone:, #performSelectorOnMainThread:withObject:waitUntilDone:modes:, print, printf, #private_methods, proc, #protected_methods, #public_method, #public_methods, #public_send, putc, puts, raise, rand, readline, readlines, #replacementObjectForCoder:, #replacementObjectForKeyedArchiver:, require, resolveClassMethod:, resolveInstanceMethod:, #respond_to?, #respond_to_missing?, select, #send, setVersion:, #singleton_methods, sprintf, srand, superclass, #taint, #tainted?, #tap, test, throw, #to_plist, #to_s, trace_var, trap, #trust, #untaint, untrace_var, #untrust, #untrusted?, version

Constructor Details

This class inherits a constructor from NSObject

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class NSObject

Class Method Details

+ (const NSStringEncoding) availableStringEncodings

Returns a zero-terminated list of the encodings string objects support in the application’s environment. Among the more commonly used encodings are: NSASCIIStringEncoding NSUnicodeStringEncoding NSISOLatin1StringEncoding NSISOLatin2StringEncoding NSSymbolStringEncodingSee the “Constants” section for a larger list and descriptions of many supported encodings. In addition to those encodings listed here, you can also use the encodings defined for CFString in Core Foundation; you just need to call the CFStringConvertEncodingToNSStringEncoding function to convert them to a usable format.

Returns:

  • (const NSStringEncoding)

    A zero-terminated list of the encodings string objects support in the application’s environment.

+ (NSStringEncoding) defaultCStringEncoding

Returns the C-string encoding assumed for any method accepting a C string as an argument. This method returns a user-dependent encoding who value is derived from user’s default language and potentially other factors. You might sometimes need to use this encoding when interpreting user documents with unknown encodings, in the absence of other hints, but in general this encoding should be used rarely, if at all. Note that some potential values might result in unexpected encoding conversions of even fairly straightforward NSString content—for example, punctuation characters with a bidirectional encoding.Methods that accept a C string as an argument use …CString… in the keywords for such arguments: for example, stringWithCString:—note, though, that these are deprecated. The default C-string encoding is determined from system information and can’t be changed programmatically for an individual process. See “String Encodings” for a full list of supported encodings.

Returns:

  • (NSStringEncoding)

    The C-string encoding assumed for any method accepting a C string as an argument.

+ (String) localizedNameOfStringEncoding(encoding)

Returns a human-readable string giving the name of a given encoding.

Parameters:

  • encoding (NSStringEncoding)

    A string encoding.

Returns:

  • (String)

    A human-readable string giving the name of encoding in the current locale’s language.

+ (Object) localizedStringWithFormat(format, ...)

Returns a string created by using a given format string as a template into which the remaining argument values are substituted according to the user’s default locale. This method is equivalent to using initWithFormat:locale: and passing [[NSUserDefaults standardUserDefaults] dictionaryRepresentation] as the locale argument.As an example of formatting, this method replaces the decimal according to the locale in %f and %d substitutions, and calls descriptionWithLocale: instead of description where necessary.This code excerpt creates a string from another string and a float: The resulting string has the value “Cost: 1234.560000n” if the locale is en_US, and “Cost: 1234,560000n” if the locale is fr_FR.See “Formatting String Objects” for more information.

Parameters:

  • format

    A format string. See “Formatting String Objects” for examples of how to use this method, and “String Format Specifiers” for a list of format specifiers. This value must not be nil.Important: Raises an NSInvalidArgumentException if format is nil.

  • ...

    A comma-separated list of arguments to substitute into format.

Returns:

  • (Object)

    A string created by using format as a template into which the following argument values are substituted according to the formatting information to the user’s default locale.

+ (String) pathWithComponents(components)

Returns a string built from the strings in a given array by concatenating them with a path separator between each pair. This method doesn’t clean up the path created; use stringByStandardizingPath to resolve empty components, references to the parent directory, and so on.

Parameters:

  • components (Array)

    An array of NSString objects representing a file path. To create an absolute path, use a slash mark (“/”) as the first component. To include a trailing path divider, use an empty string as the last component.

Returns:

  • (String)

    A string built from the strings in components by concatenating them (in the order they appear in the array) with a path separator between each pair.

+ (Object) string

Returns an empty string.

Returns:

  • (Object)

    An empty string.

+ (Object) stringWithCharacters(chars, length:length)

Returns a string containing a given number of characters taken from a given C array of Unicode characters.

Parameters:

  • chars (const unichar)

    A C array of Unicode characters; the value must not be NULL.Important: Raises an exception if chars is NULL, even if length is 0.

  • length (Integer)

    The number of characters to use from chars.

Returns:

  • (Object)

    A string containing length Unicode characters taken (starting with the first) from chars.

+ (Object) stringWithContentsOfFile(path, encoding:enc, error:error)

Returns a string created by reading data from the file at a given path interpreted using a given encoding.

Parameters:

  • path (String)

    A path to a file.

  • enc (NSStringEncoding)

    The encoding of the file at path.

  • error (Pointer)

    If an error occurs, upon returns contains an NSError object that describes the problem. If you are not interested in possible errors, pass in NULL.

Returns:

  • (Object)

    A string created by reading data from the file named by path using the encoding, enc. If the file can’t be opened or there is an encoding error, returns nil.

+ (Object) stringWithContentsOfFile(path, usedEncoding:enc, error:error)

Returns a string created by reading data from the file at a given path and returns by reference the encoding used to interpret the file. This method attempts to determine the encoding of the file at path.

Parameters:

  • path (String)

    A path to a file.

  • enc (NSStringEncoding)

    Upon return, if the file is read successfully, contains the encoding used to interpret the file at path.

  • error (Pointer)

    If an error occurs, upon returns contains an NSError object that describes the problem. If you are not interested in possible errors, you may pass in NULL.

Returns:

  • (Object)

    A string created by reading data from the file named by path. If the file can’t be opened or there is an encoding error, returns nil.

+ (Object) stringWithContentsOfURL(url, encoding:enc, error:error)

Returns a string created by reading data from a given URL interpreted using a given encoding.

Parameters:

  • url (NSURL)

    The URL to read.

  • enc (NSStringEncoding)

    The encoding of the data at url.

  • error (Pointer)

    If an error occurs, upon returns contains an NSError object that describes the problem. If you are not interested in possible errors, you may pass in NULL.

Returns:

  • (Object)

    A string created by reading data from URL using the encoding, enc. If the URL can’t be opened or there is an encoding error, returns nil.

+ (Object) stringWithContentsOfURL(url, usedEncoding:enc, error:error)

Returns a string created by reading data from a given URL and returns by reference the encoding used to interpret the data. This method attempts to determine the encoding at url.

Parameters:

  • url (NSURL)

    The URL from which to read data.

  • enc (NSStringEncoding)

    Upon return, if url is read successfully, contains the encoding used to interpret the data.

  • error (Pointer)

    If an error occurs, upon returns contains an NSError object that describes the problem. If you are not interested in possible errors, you may pass in NULL.

Returns:

  • (Object)

    A string created by reading data from url. If the URL can’t be opened or there is an encoding error, returns nil.

+ (Object) stringWithCString(cString, encoding:enc)

Returns a string containing the bytes in a given C array, interpreted according to a given encoding. If cString is not a NULL-terminated C string, or encoding does not match the actual encoding, the results are undefined.

Parameters:

  • cString (const char)

    A C array of bytes. The array must end with a NULL character; intermediate NULL characters are not allowed.

  • enc (NSStringEncoding)

    The encoding of cString.

Returns:

  • (Object)

    A string containing the characters described in cString.

+ (Object) stringWithFormat(format, ...)

Returns a string created by using a given format string as a template into which the remaining argument values are substituted. This method is similar to localizedStringWithFormat:, but using the canonical locale to format numbers. This is useful, for example, if you want to produce “non-localized” formatting which needs to be written out to files and parsed back later.

Parameters:

  • format

    A format string. See “Formatting String Objects” for examples of how to use this method, and “String Format Specifiers” for a list of format specifiers. This value must not be nil.Important: Raises an NSInvalidArgumentException if format is nil.

  • ...

    A comma-separated list of arguments to substitute into format.

Returns:

  • (Object)

    A string created by using format as a template into which the remaining argument values are substituted according to the canonical locale.

+ (Object) stringWithString(aString)

Returns a string created by copying the characters from another given string.

Parameters:

  • aString (String)

    The string from which to copy characters. This value must not be nil.Important: Raises an NSInvalidArgumentException if aString is nil.

Returns:

  • (Object)

    A string created by copying the characters from aString.

+ (Object) stringWithUTF8String(bytes)

Returns a string created by copying the data from a given C array of UTF8-encoded bytes.

Parameters:

  • bytes (const char)

    A NULL-terminated C array of bytes in UTF8 encoding. Important: Raises an exception if bytes is NULL.

Returns:

  • (Object)

    A string created by copying the data from bytes.

Instance Method Details

- (Boolean) boolValue

Returns the Boolean value of the receiver’s text. The method assumes a decimal representation and skips whitespace at the beginning of the string. It also skips initial whitespace characters, or optional -/+ sign followed by zeroes.

Returns:

  • (Boolean)

    The Boolean value of the receiver’s text. Returns YES on encountering one of “Y”, “y”, “T”, “t”, or a digit 1-9—the method ignores any trailing characters. Returns NO if the receiver doesn’t begin with a valid decimal text representation of a number.

- (Boolean) canBeConvertedToEncoding(encoding)

Returns a Boolean value that indicates whether the receiver can be converted to a given encoding without loss of information. If you plan to actually convert a string, the dataUsingEncoding:... methods return nil on failure, so you can avoid the overhead of invoking this method yourself by simply trying to convert the string.

Parameters:

  • encoding (NSStringEncoding)

    A string encoding.

Returns:

  • (Boolean)

    YES if the receiver can be converted to encoding without loss of information. Returns NO if characters would have to be changed or deleted in the process of changing encodings.

- (String) capitalizedString

Returns a capitalized representation of the receiver. A “word” here is any sequence of characters delimited by spaces, tabs, or line terminators (listed under getLineStart:end:contentsEnd:forRange:). Other common word delimiters such as hyphens and other punctuation aren’t considered, so this method may not generally produce the desired results for multiword strings.Case transformations aren’t guaranteed to be symmetrical or to produce strings of the same lengths as the originals. See lowercaseString for an example.Note: This method performs the canonical (non-localized) mapping. It is suitable for programming operations that require stable results not depending on the user’s locale preference. For localized case mapping for strings presented to users, use the capitalizedStringWithLocale: method.

Returns:

  • (String)

    A string with the first character from each word in the receiver changed to its corresponding uppercase value, and all remaining characters set to their corresponding lowercase values.

- (String) capitalizedStringWithLocale(locale)

Returns a capitalized representation of the receiver using the specified locale. For the user preference locale setting, pass the result of the NSLocale method currentLocale.

Parameters:

  • locale (NSLocale)

    The locale. Passing nil indicates the canonical mapping.

Returns:

  • (String)

    A capitalized string using the locale.

- (NSComparisonResult) caseInsensitiveCompare(aString)

Returns the result of invoking compare:options: with NSCaseInsensitiveSearch as the only option. If you are comparing strings to present to the end-user, you should typically use localizedCaseInsensitiveCompare: instead.

Parameters:

  • aString (String)

    The string with which to compare the receiver. This value must not be nil. If this value is nil, the behavior is undefined and may change in future versions of OS X.

Returns:

  • (NSComparisonResult)

    The result of invoking compare:options: with NSCaseInsensitiveSearch as the only option.

- (Integer) characterAtIndex(index)

Returns the character at a given array position. Raises an NSRangeException if index lies beyond the end of the receiver.

Parameters:

  • index (Integer)

    The index of the character to retrieve. The index value must not lie outside the bounds of the receiver.

Returns:

  • (Integer)

    The character at the array position given by index.

- (String) commonPrefixWithString(aString, options:mask)

Returns a string containing characters the receiver and a given string have in common, starting from the beginning of each up to the first characters that aren’t equivalent. The returned string is based on the characters of the receiver. For example, if the receiver is “Ma¨dchen” and aString is “Mädchenschule”, the string returned is “Ma¨dchen”, not “Mädchen”.

Parameters:

  • aString (String)

    The string with which to compare the receiver.

  • mask (NSStringCompareOptions)

    Options for the comparison. The following search options may be specified by combining them with the C bitwise OR operator: NSCaseInsensitiveSearch, NSLiteralSearch. See String Programming Guide for details on these options.

Returns:

  • (String)

    A string containing characters the receiver and aString have in common, starting from the beginning of each up to the first characters that aren’t equivalent.

- (NSComparisonResult) compare(aString)

Returns the result of invoking compare:options:range: with no options and the receiver’s full extent as the range. If you are comparing strings to present to the end-user, you should typically use localizedCompare: or localizedCaseInsensitiveCompare: instead.

Parameters:

  • aString (String)

    The string with which to compare the receiver.This value must not be nil. If this value is nil, the behavior is undefined and may change in future versions of OS X.

Returns:

  • (NSComparisonResult)

    The result of invoking compare:options:range: with no options and the receiver’s full extent as the range.

- (NSComparisonResult) compare(aString, options:mask)

Returns the result of invoking compare:options:range: with a given mask as the options and the receiver’s full extent as the range. If you are comparing strings to present to the end-user, you should typically use localizedCompare: or localizedCaseInsensitiveCompare: instead, or use compare:options:range:locale: and pass the user’s locale.

Parameters:

  • aString (String)

    The string with which to compare the receiver. This value must not be nil. If this value is nil, the behavior is undefined and may change in future versions of OS X.

  • mask (NSStringCompareOptions)

    Options for the search—you can combine any of the following using a C bitwise OR operator: NSCaseInsensitiveSearch, NSLiteralSearch, NSNumericSearch. See String Programming Guide for details on these options.

Returns:

  • (NSComparisonResult)

    The result of invoking compare:options:range: with a given mask as the options and the receiver’s full extent as the range.

- (NSComparisonResult) compare(aString, options:mask, range:range)

Returns the result of invoking compare:options:range:locale: with a nil locale. If you are comparing strings to present to the end-user, you should typically use compare:options:range:locale: instead and pass the user’s locale (currentLocale [NSLocale]).

Parameters:

  • aString (String)

    The string with which to compare the range of the receiver specified by range. This value must not be nil. If this value is nil, the behavior is undefined and may change in future versions of OS X.

  • mask (NSStringCompareOptions)

    Options for the search—you can combine any of the following using a C bitwise OR operator: NSCaseInsensitiveSearch, NSLiteralSearch, NSNumericSearch.See String Programming Guide for details on these options.

  • range (NSRange)

    The range of the receiver over which to perform the comparison. The range must not exceed the bounds of the receiver.Important: Raises an NSRangeException if range exceeds the bounds of the receiver.

Returns:

  • (NSComparisonResult)

    The result of invoking compare:options:range:locale: with a nil locale.

- (NSComparisonResult) compare(aString, options:mask, range:range, locale:locale)

Returns an NSComparisonResult value that indicates the lexical ordering of a specified range within the receiver and a given string.

Parameters:

  • aString (String)

    The string with which to compare the range of the receiver specified by range. This value must not be nil. If this value is nil, the behavior is undefined and may change in future versions of OS X.

  • mask (NSStringCompareOptions)

    Options for the search—you can combine any of the following using a C bitwise OR operator: NSCaseInsensitiveSearch, NSLiteralSearch, NSNumericSearch.See String Programming Guide for details on these options.

  • range (NSRange)

    The range of the receiver over which to perform the comparison. The range must not exceed the bounds of the receiver.Important: Raises an NSRangeException if range exceeds the bounds of the receiver.

  • locale (Object)

    An instance of NSLocale. If this value not nil and is not an instance of NSLocale, uses the current locale instead. If you are comparing strings to present to the end-user, you should typically pass the user’s locale (currentLocale [NSLocale]).The locale argument affects both equality and ordering algorithms. For example, in some locales, accented characters are ordered immediately after the base; other locales order them after “z”.

Returns:

  • (NSComparisonResult)

    NSOrderedAscending if the substring of the receiver given by range precedes aString in lexical ordering for the locale given in dict, NSOrderedSame if the substring of the receiver and aString are equivalent in lexical value, and NSOrderedDescending if the substring of the receiver follows aString.

- (Integer) completePathIntoString(outputName, caseSensitive:flag, matchesIntoArray:outputArray, filterTypes:filterTypes)

Interprets the receiver as a path in the file system and attempts to perform filename completion, returning a numeric value that indicates whether a match was possible, and by reference the longest path that matches the receiver. You can check for the existence of matches without retrieving by passing NULL as outputArray.Note that this method only works with file paths (not, for example, string representations of URLs).

Parameters:

  • outputName (Pointer)

    Upon return, contains the longest path that matches the receiver.

  • flag (Boolean)

    If YES, the methods considers case for possible completions.

  • outputArray (Pointer)

    Upon return, contains all matching filenames.

  • filterTypes (Array)

    An array of NSString objects specifying path extensions to consider for completion. only paths whose extensions (not including the extension separator) match one of those strings.

Returns:

  • (Integer)

    0 if no matches are found and 1 if exactly one match is found. In the case of multiple matches, returns the actual number of matching paths if outputArray is provided, or simply a positive value if outputArray is NULL.

- (Array) componentsSeparatedByCharactersInSet(separator)

Returns an array containing substrings from the receiver that have been divided by characters in a given set. The substrings in the array appear in the order they did in the receiver. Adjacent occurrences of the separator characters produce empty strings in the result. Similarly, if the string begins or ends with separator characters, the first or last substring, respectively, is empty.

Parameters:

  • separator (NSCharacterSet)

    A character set containing the characters to to use to split the receiver. Must not be nil.

Returns:

  • (Array)

    An NSArray object containing substrings from the receiver that have been divided by characters in separator.

- (Array) componentsSeparatedByString(separator)

Returns an array containing substrings from the receiver that have been divided by a given separator. The substrings in the array appear in the order they did in the receiver. Adjacent occurrences of the separator string produce empty strings in the result. Similarly, if the string begins or ends with the separator, the first or last substring, respectively, is empty. For example, this code fragment: produces an array { @“Norman”, @“Stanley”, @“Fletcher” }.If list begins with a comma and space—for example, “, Norman, Stanley, Fletcher”—the array has these contents: { @“”, @“Norman”, @“Stanley”, @“Fletcher” }If list has no separators—for example, “Norman”—the array contains the string itself, in this case { @“Norman” }.

Parameters:

  • separator (String)

    The separator string.

Returns:

  • (Array)

    An NSArray object containing substrings from the receiver that have been divided by separator.

- (const char) cStringUsingEncoding(encoding)

Returns a representation of the receiver as a C string using a given encoding. The returned C string is guaranteed to be valid only until either the receiver is freed, or until the current autorelease pool is emptied, whichever occurs first. You should copy the C string or use getCString:maxLength:encoding: if it needs to store the C string beyond this time.You can use canBeConvertedToEncoding: to check whether a string can be losslessly converted to encoding. If it can’t, you can use dataUsingEncoding:allowLossyConversion: to get a C-string representation using encoding, allowing some loss of information (note that the data returned by dataUsingEncoding:allowLossyConversion: is not a strict C-string since it does not have a NULL terminator).

Parameters:

  • encoding (NSStringEncoding)

    The encoding for the returned C string.

Returns:

  • (const char)

    A C string representation of the receiver using the encoding specified by encoding. Returns NULL if the receiver cannot be losslessly converted to encoding.

- (NSData) dataUsingEncoding(encoding)

Returns an NSData object containing a representation of the receiver encoded using a given encoding.

Parameters:

  • encoding (NSStringEncoding)

    A string encoding.

Returns:

  • (NSData)

    The result of invoking dataUsingEncoding:allowLossyConversion: with NO as the second argument (that is, requiring lossless conversion).

- (NSData) dataUsingEncoding(encoding, allowLossyConversion:flag)

Returns an NSData object containing a representation of the receiver encoded using a given encoding. If flag is YES and the receiver can’t be converted without losing some information, some characters may be removed or altered in conversion. For example, in converting a character from NSUnicodeStringEncoding to NSASCIIStringEncoding, the character ‘Á’ becomes ‘A’, losing the accent.This method creates an external representation (with a byte order marker, if necessary, to indicate endianness) to ensure that the resulting NSData object can be written out to a file safely. The result of this method, when lossless conversion is made, is the default “plain text” format for encoding and is the recommended way to save or transmit a string object.

Parameters:

  • encoding (NSStringEncoding)

    A string encoding.

  • flag (Boolean)

    If YES, then allows characters to be removed or altered in conversion.

Returns:

  • (NSData)

    An NSData object containing a representation of the receiver encoded using encoding. Returns nil if flag is NO and the receiver can’t be converted without losing some information (such as accents or case).

- (String) decomposedStringWithCanonicalMapping

Returns a string made by normalizing the receiver’s contents using Form D.

Returns:

  • (String)

    A string made by normalizing the receiver’s contents using the Unicode Normalization Form D.

- (String) decomposedStringWithCompatibilityMapping

Returns a string made by normalizing the receiver’s contents using Form KD.

Returns:

  • (String)

    A string made by normalizing the receiver’s contents using the Unicode Normalization Form KD.

- (String) description

Returns the receiver.

Returns:

- (Float) doubleValue

Returns the floating-point value of the receiver’s text as a double. This method skips any whitespace at the beginning of the string. This method uses formatting information stored in the non-localized value; use an NSScanner object for localized scanning of numeric values from a string.

Returns:

  • (Float)

    The floating-point value of the receiver’s text as a double. Returns HUGE_VAL or –HUGE_VAL on overflow, 0.0 on underflow. Returns 0.0 if the receiver doesn’t begin with a valid text representation of a floating-point number.

- (Object) encode

on RubyStrings.

- (Object) encode!

- (Object) enumerateLinesUsingBlock(block)

Enumerates all the lines in a string.

Parameters:

  • block

    The block executed for the enumeration.The block takes two arguments:lineThe current line of the string being enumerated. The line contains just the contents of the line, without the line terminators.stopA reference to a Boolean value that the block can use to stop the enumeration by setting *stop = YES; it should not touch *stop otherwise.

  • line

    The current line of the string being enumerated. The line contains just the contents of the line, without the line terminators.

  • stop

    A reference to a Boolean value that the block can use to stop the enumeration by setting *stop = YES; it should not touch *stop otherwise.

Returns:

- (Object) enumerateLinguisticTagsInRange(range, scheme:tagScheme, options:opts, orthography:orthography, usingBlock:block)

Performs linguistic analysis on the specified string by enumerating the specific range of the string, providing the Block with the located tags. This is a convenience method. It is the equivalent of creating an instance of NSLinguisticTagger, specifying the receiver as the string to be analyzed, and the orthography (or nil) and then invoking the NSLinguisticTagger method or enumerateTagsInRange:scheme:options:usingBlock:.

Parameters:

  • range

    The range of the string to analyze.

  • tagScheme

    The tag scheme to use. See Linguistic Tag Schemes for supported values.

  • opts

    The linguistic tagger options to use. See NSLinguisticTaggerOptionsfor the constants. These constants can be combined using the C-Bitwise OR operator.

  • orthography

    The orthography of the string. If nil, the linguistic tagger will attempt to determine the orthography from the string content.

  • block

    The Block to apply to the string.The block takes four arguments:tagThe tag scheme for the token. The opts parameter specifies the types of tagger options that are located.tokenRangeThe range of a string matching the tag scheme.sentenceRangeThe range of the sentence in which the token is found.stopA reference to a Boolean value. The block can set the value to YES to stop further processing of the array. The stop argument is an out-only argument. You should only ever set this Boolean to YES within the Block.

  • tag

    The tag scheme for the token. The opts parameter specifies the types of tagger options that are located.

  • tokenRange

    The range of a string matching the tag scheme.

  • sentenceRange

    The range of the sentence in which the token is found.

  • stop

    A reference to a Boolean value. The block can set the value to YES to stop further processing of the array. The stop argument is an out-only argument. You should only ever set this Boolean to YES within the Block.

Returns:

- (Object) enumerateSubstringsInRange(range, options:opts, usingBlock:block)

Enumerates the substrings of the specified type in the specified range of the string. If this method is sent to an instance of NSMutableString, mutation (deletion, addition, or change) is allowed, as long as it is within enclosingRange. After a mutation, the enumeration continues with the range immediately following the processed range, after the length of the processed range is adjusted for the mutation. (The enumerator assumes any change in length occurs in the specified range.) For example, if the block is called with a range starting at location N, and the block deletes all the characters in the supplied range, the next call will also pass N as the index of the range. This is the case even if mutation of the previous range changes the string in such a way that the following substring would have extended to include the already enumerated range. For example, if the string "Hello World" is enumerated via words, and the block changes "Hello " to "Hello", thus forming "HelloWorld", the next enumeration will return "World" rather than "HelloWorld".

Parameters:

  • range

    The range within the string to enumerate substrings.

  • opts

    Options specifying types of substrings and enumeration styles.

  • block

    The block executed for the enumeration.The block takes four arguments:substringThe enumerated string.substringRangeThe range of the enumerated string in the receiver.enclosingRangeThe range that includes the substring as well as any separator or filler characters that follow. For instance, for lines, enclosingRange contains the line terminators. The enclosingRange for the first string enumerated also contains any characters that occur before the string. Consecutive enclosing ranges are guaranteed not to overlap, and every single character in the enumerated range is included in one and only one enclosing range.stopA reference to a Boolean value that the block can use to stop the enumeration by setting *stop = YES; it should not touch *stop otherwise.

  • substring

    The enumerated string.

  • substringRange

    The range of the enumerated string in the receiver.

  • enclosingRange

    The range that includes the substring as well as any separator or filler characters that follow. For instance, for lines, enclosingRange contains the line terminators. The enclosingRange for the first string enumerated also contains any characters that occur before the string. Consecutive enclosing ranges are guaranteed not to overlap, and every single character in the enumerated range is included in one and only one enclosing range.

  • stop

    A reference to a Boolean value that the block can use to stop the enumeration by setting *stop = YES; it should not touch *stop otherwise.

Returns:

- (NSStringEncoding) fastestEncoding

Returns the fastest encoding to which the receiver may be converted without loss of information. “Fastest” applies to retrieval of characters from the string. This encoding may not be space efficient.

Returns:

  • (NSStringEncoding)

    The fastest encoding to which the receiver may be converted without loss of information.

- (const char) fileSystemRepresentation

Returns a file system-specific representation of the receiver. The returned C string will be automatically freed just as a returned object would be released; your code should copy the representation or use getFileSystemRepresentation:maxLength: if it needs to store the representation outside of the autorelease context in which the representation is created.Raises an NSCharacterConversionException if the receiver can’t be represented in the file system’s encoding. It also raises an exception if the string contains no characters.Note that this method only works with file paths (not, for example, string representations of URLs). To convert a char * path (such as you might get from a C library routine) to an NSString object, use NSFileManager‘s stringWithFileSystemRepresentation:length: method.

Returns:

  • (const char)

    A file system-specific representation of the receiver, as described for getFileSystemRepresentation:maxLength:.

- (Float) floatValue

Returns the floating-point value of the receiver’s text as a float. This method uses formatting information stored in the non-localized value; use an NSScanner object for localized scanning of numeric values from a string.

Returns:

  • (Float)

    The floating-point value of the receiver’s text as a float, skipping whitespace at the beginning of the string. Returns HUGE_VAL or –HUGE_VAL on overflow, 0.0 on underflow. Also returns 0.0 if the receiver doesn’t begin with a valid text representation of a floating-point number.

- (Boolean) getBytes(buffer, maxLength:maxBufferCount, usedLength:usedBufferCount, encoding:encoding, options:options, range:range, remainingRange:leftover)

Gets a given range of characters as bytes in a specified encoding. Conversion might stop when the buffer fills, but it might also stop when the conversion isn't possible due to the chosen encoding.

Parameters:

  • buffer (Object)

    A buffer into which to store the bytes from the receiver. The returned bytes are not NULL-terminated.

  • maxBufferCount (Integer)

    The maximum number of bytes to write to buffer.

  • usedBufferCount (Integer)

    The number of bytes used from buffer. Pass NULL if you do not need this value.

  • encoding (NSStringEncoding)

    The encoding to use for the returned bytes.

  • options (NSStringEncodingConversionOptions)

    A mask to specify options to use for converting the receiver’s contents to encoding (if conversion is necessary).

  • range (NSRange)

    The range of characters in the receiver to get.

  • leftover (NSRangePointer)

    The remaining range. Pass NULL If you do not need this value.

Returns:

  • (Boolean)

    YES if some characters were converted, otherwise NO.

- (Object) getCharacters(buffer, range:aRange)

Copies characters from a given range in the receiver into a given buffer. This method does not add a NULL character. The abstract implementation of this method uses characterAtIndex: repeatedly, correctly extracting the characters, though very inefficiently. Subclasses should override it to provide a fast implementation.

Parameters:

  • buffer (Integer)

    Upon return, contains the characters from the receiver. buffer must be large enough to contain the characters in the range aRange (aRange.length*sizeof(unichar)).

  • aRange (NSRange)

    The range of characters to retrieve. The range must not exceed the bounds of the receiver.Important: Raises an NSRangeException if any part of aRange lies beyond the bounds of the receiver.

Returns:

- (Boolean) getCString(buffer, maxLength:maxBufferCount, encoding:encoding)

Converts the receiver’s content to a given encoding and stores them in a buffer. Note that in the treatment of the maxBufferCount argument, this method differs from the deprecated getCString:maxLength: method which it replaces. (The buffer should include room for maxBufferCount bytes; this number should accommodate the expected size of the return value plus the NULL termination byte, which this method adds.)You can use canBeConvertedToEncoding: to check whether a string can be losslessly converted to encoding. If it can’t, you can use dataUsingEncoding:allowLossyConversion: to get a C-string representation using encoding, allowing some loss of information (note that the data returned by dataUsingEncoding:allowLossyConversion: is not a strict C-string since it does not have a NULL terminator).

Parameters:

  • buffer (Integer)

    Upon return, contains the converted C-string plus the NULL termination byte. The buffer must include room for maxBufferCount bytes.

  • maxBufferCount (Integer)

    The maximum number of bytes in the string to return in buffer (including the NULL termination byte).

  • encoding (NSStringEncoding)

    The encoding for the returned C string.

Returns:

  • (Boolean)

    YES if the operation was successful, otherwise NO. Returns NO if conversion is not possible due to encoding errors or if buffer is too small.

- (Boolean) getFileSystemRepresentation(buffer, maxLength:maxLength)

Interprets the receiver as a system-independent path and fills a buffer with a C-string in a format and encoding suitable for use with file-system calls. This method operates by replacing the abstract path and extension separator characters (‘/’ and ‘.’ respectively) with their equivalents for the operating system. If the system-specific path or extension separator appears in the abstract representation, the characters it is converted to depend on the system (unless they’re identical to the abstract separators).Note that this method only works with file paths (not, for example, string representations of URLs).The following example illustrates the use of the maxLength argument. The first method invocation returns failure as the file representation of the string (@“/mach_kernel”) is 12 bytes long and the value passed as the maxLength argument (12) does not allow for the addition of a NULL termination byte.

Parameters:

  • buffer (Integer)

    Upon return, contains a C-string that represent the receiver as as a system-independent path, plus the NULL termination byte. The size of buffer must be large enough to contain maxLength bytes.

  • maxLength (Integer)

    The maximum number of bytes in the string to return in buffer (including a terminating NULL character, which this method adds).

Returns:

  • (Boolean)

    YES if buffer is successfully filled with a file-system representation, otherwise NO (for example, if maxLength would be exceeded or if the receiver can’t be represented in the file system’s encoding).

- (Object) getLineStart(startIndex, end)

Returns by reference the beginning of the first line and the end of the last line touched by the given range. A line is delimited by any of these characters, the longest possible sequence being preferred to any shorter:U+000D (r or CR) U+2028 (Unicode line separator) U+000A (n or LF) U+2029 (Unicode paragraph separator) rn, in that order (also known as CRLF)If aRange is contained with a single line, of course, the returned indexes all belong to that line. You can use the results of this method to construct ranges for lines by using the start index as the range’s location and the difference between the end index and the start index as the range’s length.This method detects all invalid ranges (including those with negative lengths). For applications linked against OS X v10.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.

Parameters:

  • startIndex (Integer)

    Upon return, contains the index of the first character of the line containing the beginning of aRange. Pass NULL if you do not need this value (in which case the work to compute the value isn’t performed).

  • lineEndIndex (Integer)

    Upon return, contains the index of the first character past the terminator of the line containing the end of aRange. Pass NULL if you do not need this value (in which case the work to compute the value isn’t performed).

  • contentsEndIndex (Integer)

    Upon return, contains the index of the first character of the terminator of the line containing the end of aRange. Pass NULL if you do not need this value (in which case the work to compute the value isn’t performed).

  • aRange (NSRange)

    A range within the receiver. The value must not exceed the bounds of the receiver. Important: Raises an NSRangeException if any part of aRange lies beyond the end of the string.

Returns: