NSString (misc)


Declared In:
NSString+misc.h


Category Description

This category contains methods used to support Watson tool functionality, specifically in searching within strings and for performing string to HTML and URL encoded text conversions.


Method Types

String matching
- rangeBetweenString:andString:
- rangeBetweenString:andString:options:
- rangeBetweenString:andString:options:range:
- rangeFromString:toString:
- rangeFromString:toString:options:
- rangeFromString:toString:options:range:
Replacement in between delimeters
- replaceAllTextBetweenString:andString:fromDictionary:options:range:
- replaceAllTextBetweenString:andString:fromDictionary:options:
- replaceAllTextBetweenString:andString:fromDictionary:
XML processing
- xmlEscapedString
- unescapeXML
Other string utilities
- flattenHTML
- urlDecode
- urlEncode
- encodeLegally
- stripQuotes
- hyperlink
- digitsOnly
- condenseWhiteSpace
- trimWhiteSpace
- removeWhiteSpace
- crunchWhiteSpace
- checksum
- lossyASCIIString
- floatVersion
- componentsSeparatedByLineSeparators

Instance Methods

checksum

- (int)checksum

Return a checksum of the string, calculated by adding the Unicode value of each character in the string into an integer total, ignoring overflow.


componentsSeparatedByLineSeparators

- (NSArray *)componentsSeparatedByLineSeparators

Split a string into lines separated by any of the various newline characters. Equivalent to componentsSeparatedByString:@"\n" but it works with the different line separators: \r, \n, \r\n, 0x2028, 0x2029


condenseWhiteSpace

- (NSString *)condenseWhiteSpace

Return a string where runs of multiple white space characters (space, tab, all types of newline, return, forced space, and Unicode U+FFFC, Object replacement character) are condensed down to a single space. Trim off any leading/trailing white space.


crunchWhiteSpace

- (NSString *)crunchWhiteSpace

Return a string where runs of multiple white space characters (space, tab, all types of newline, return, forced space, and Unicode U+FFFC, Object replacement character) are condensed down to a single one of those character.


digitsOnly

- (NSString *)digitsOnly

Return a string consisting only of the digits in the string. For example, (916) 692-1560 is converted to 9166921560.


encodeLegally

- (NSString *)encodeLegally

Fix a URL-encoded string that may have some characters that makes NSURL barf. It basicaly re-encodes the string, but ignores escape characters + and %, and also #.


flattenHTML

- (NSString *)flattenHTML

Remove HTML tags to turn a fragment of HTML into a piece of plain text. All characters between < and > are removed. Escape sequences such as &amp; are converted into their character equivalents.


floatVersion

- (float)floatVersion

Take out all but the first decimal point, and turn into a floating number. This isn't going to do well with numbers >=10 between the decimal points 1.0 -> 1.0 1.1 -> 1.1 1.1.1 -> 1.11 1.2.3.4 -> 1.234 but 1.10 -> 1.1 and 1.1 -> 1.1 ! etc.


hyperlink

- (NSAttributedString *)hyperlink

Convert the given string into an attributed string with attributes resembling a hypertext link, blue with underline.


lossyASCIIString

- (NSString *)lossyASCIIString

Convert a string to its ASCII equivalent, lossily.


rangeBetweenString:andString:

- (NSRange)rangeBetweenString:(NSString *)inString1 andString:(NSString *)inString2

Find a string between the two given strings with the default options; the delimeter strings are not included in the result.


rangeBetweenString:andString:options:

- (NSRange)rangeBetweenString:(NSString *)inString1 andString:(NSString *)inString2 options:(unsigned)inMask

Find a string between the two given strings with the given options inMask; the delimeter strings are not included in the result. The inMask parameter is the same as is passed to [NSString rangeOfString:options:range:].


rangeBetweenString:andString:options:range:

- (NSRange)rangeBetweenString:(NSString *)inString1 andString:(NSString *)inString2 options:(unsigned)inMask range:(NSRange)inSearchRange

Find a string between the two given strings with the given options inMask and the given substring range inSearchRange; the delimeter strings are not included in the result. The inMask parameter is the same as is passed to [NSString rangeOfString:options:range:].


rangeFromString:toString:

- (NSRange)rangeFromString:(NSString *)inString1 toString:(NSString *)inString2

Find a string from one string to another with the default options; the delimeter strings are included in the result.


rangeFromString:toString:options:

- (NSRange)rangeFromString:(NSString *)inString1 toString:(NSString *)inString2 options:(unsigned)inMask

Find a string from one string to another with the given options inMask; the delimeter strings are included in the result. The inMask parameter is the same as is passed to [NSString rangeOfString:options:range:].


rangeFromString:toString:options:range:

- (NSRange)rangeFromString:(NSString *)inString1 toString:(NSString *)inString2 options:(unsigned)inMask range:(NSRange)inSearchRange

Find a string from one string to another with the given options inMask and the given substring range inSearchRange; the delimeter strings are included in the result. The inMask parameter is the same as is passed to [NSString rangeOfString:options:range:].


removeWhiteSpace

- (NSString *)removeWhiteSpace

Remove all white space from a string.


replaceAllTextBetweenString:andString:fromDictionary:

- (NSString *)replaceAllTextBetweenString:(NSString *)inString1 andString:(NSString *)inString2 fromDictionary:(NSDictionary *)inDict

Find a string between the two given strings with the default options; the delimeter strings are not included in the result.


replaceAllTextBetweenString:andString:fromDictionary:options:

- (NSString *)replaceAllTextBetweenString:(NSString *)inString1 andString:(NSString *)inString2 fromDictionary:(NSDictionary *)inDict options:(unsigned)inMask

Find a string between the two given strings with the given options inMask; the delimeter strings are not included in the result. The inMask parameter is the same as is passed to [NSString rangeOfString:options:range:].


replaceAllTextBetweenString:andString:fromDictionary:options:range:

- (NSString *)replaceAllTextBetweenString:(NSString *)inString1 andString:(NSString *)inString2 fromDictionary:(NSDictionary *)inDict options:(unsigned)inMask range:(NSRange)inSearchRange

General search-and-replace mechanism to convert text between the given delimeters. Pass in a dictionary with the keys of "from" strings, and the values of what to convert them to. If not found in the dictionary, the text will just be removed. If the dictionary passed in is nil, then the string between the delimeters will put in the place of the whole range; this could be used to just strip out the delimeters.


stripQuotes

- (NSString *)stripQuotes

Remove any leading and trailing double-quote marks and return the resulting string.


trimWhiteSpace

- (NSString *)trimWhiteSpace

Return the string with all white space (space, tab, all types of newline, return, forced space, and Unicode U+FFFC, Object replacement character) trimmed from the start and end of the string.


unescapeXML

- (NSString *)unescapeXML

Convert XML with escaped characters into a regular string


urlDecode

- (NSString *)urlDecode

Convert a URL-encoded string into a plain string, changing + into space, and nn sequences into corresponding character. This is used to convert text found in a URL line into human-readable.


urlEncode

- (NSString *)urlEncode

Convert a plain string into a new string, replacing certain characters with the equivalent percent escape sequence.


xmlEscapedString

- (NSString *)xmlEscapedString

Convert > = &gt;, etc. into their counterparts.


Version 1.1 Copyright ©2003 by Karelia Software, LLC. All Rights Reserved.