The iOS framework that grows only as fast as its documentation
NSString Methods

Functions

NSString * NIMD5HashFromString (NSString *string)
 
NSString * NISHA1HashFromString (NSString *string)
 
BOOL NIIsStringWithWhitespaceAndNewlines (NSString *string)
 
NSComparisonResult NICompareVersionStrings (NSString *string1, NSString *string2)
 
NSDictionary * NIQueryDictionaryFromStringUsingEncoding (NSString *string, NSStringEncoding encoding)
 
NSString * NIStringByAddingPercentEscapesForURLParameterString (NSString *parameter)
 
NSString * NIStringByAddingQueryDictionaryToString (NSString *string, NSDictionary *query)
 

Overview

For manipulating NSStrings.

Function Documentation

NIMD5HashFromString

Calculates an md5 hash of the string using CC_MD5.

NSString* NIMD5HashFromString:(NSString *)string;
Discussion

Treats the string as UTF8.

NISHA1HashFromString

Calculates a sha1 hash of the string using CC_SHA1.

NSString* NISHA1HashFromString:(NSString *)string;
Discussion

Treats the string as UTF8.

NIIsStringWithWhitespaceAndNewlines

Returns a Boolean value indicating whether the string is a NSString object that contains only whitespace and newlines.

BOOL NIIsStringWithWhitespaceAndNewlines:(NSString *)string;

NICompareVersionStrings

Compares two strings expressing software versions.

NSComparisonResult NICompareVersionStrings;
Discussion

The comparison is (except for the development version provisions noted below) lexicographic string comparison. So as long as the strings being compared use consistent version formats, a variety of schemes are supported. For example "3.02" < "3.03" and "3.0.2" < "3.0.3". If you mix such schemes, like trying to compare "3.02" and "3.0.3", the result may not be what you expect.

Development versions are also supported by adding an "a" character and more version info after it. For example "3.0a1" or "3.01a4". The way these are handled is as follows: if the parts before the "a" are different, the parts after the "a" are ignored. If the parts before the "a" are identical, the result of the comparison is the result of NUMERICALLY comparing the parts after the "a". If the part after the "a" is empty, it is treated as if it were "0". If one string has an "a" and the other does not (e.g. "3.0" and "3.0a1") the one without the "a" is newer.

Examples (?? means undefined):

  "3.0" = "3.0"
  "3.0a2" = "3.0a2"
  "3.0" > "2.5"
  "3.1" > "3.0"
  "3.0a1" < "3.0"
  "3.0a1" < "3.0a4"
  "3.0a2" < "3.0a19"  <-- numeric, not lexicographic
  "3.0a" < "3.0a1"
  "3.02" < "3.03"
  "3.0.2" < "3.0.3"
  "3.00" ?? "3.0"
  "3.02" ?? "3.0.3"
  "3.02" ?? "3.0.2"

NIQueryDictionaryFromStringUsingEncoding

Parses a URL query string into a dictionary where the values are arrays.

NSDictionary* NIQueryDictionaryFromStringUsingEncoding;
Discussion

A query string is one that looks like &param1=value1&param2=value2...

The resulting NSDictionary will contain keys for each parameter name present in the query. The value for each key will be an NSArray which may be empty if the key is simply present in the query. Otherwise each object in the array with be an NSString corresponding to a value in the query for that parameter.

NIStringByAddingPercentEscapesForURLParameterString

Returns a string that has been escaped for use as a URL parameter.

NSString* NIStringByAddingPercentEscapesForURLParameterString:(NSString *)parameter;

NIStringByAddingQueryDictionaryToString

Appends a dictionary of query parameters to a string, adding the ? character if necessary.

NSString* NIStringByAddingQueryDictionaryToString;