NSString(Extensions) Category Reference

Declared in NSString+Extensions.h

Overview

NSString extensions.

  rangeOfWholeString

The NSRange of the whole string.

@property (nonatomic, readonly) NSRange rangeOfWholeString

Discussion

The NSRange of the whole string.

Declared In

NSString+Extensions.h

+ stringByCombiningString:withString:

Combines two strings together. Treats nil values as empty strings.

+ (nonnull NSString *)stringByCombiningString:(nullable NSString *)stringA withString:(nullable NSString *)stringB

Parameters

stringA

The first string.

stringB

The second string.

Return Value

The combined string.

Discussion

Combines two strings together. Treats nil values as empty strings.

Declared In

NSString+Extensions.h

+ boolValueFromString:defaultValue:

Parses a boolean from the given string.

+ (BOOL)boolValueFromString:(nullable NSString *)string defaultValue:(BOOL)defaultValue

Parameters

string

The string value.

defaultValue

The default boolean value.

Return Value

The resulting boolean value.

Discussion

Parses a boolean from the given string.

If the string was nil or did not contain a valid boolean value, the default value is returned.

Declared In

NSString+Extensions.h

  urlStringByDeletingLastPathComponent

Removes the last path component from a URL string.

@property (nonatomic, readonly, nonnull) NSString *urlStringByDeletingLastPathComponent

Discussion

Removes the last path component from a URL string.

Declared In

NSString+Extensions.h

  urlStringByDeletingPathExtension

Removes the path extension from a URL string.

@property (nonatomic, readonly, nonnull) NSString *urlStringByDeletingPathExtension

Discussion

Removes the path extension from a URL string.

Declared In

NSString+Extensions.h

– urlStringByAppendingPathExtension:

Appends the given path extension to the URL string.

- (nonnull NSString *)urlStringByAppendingPathExtension:(nonnull NSString *)pathExtension

Parameters

pathExtension

The path extension to append.

Return Value

The resulting URL string.

Discussion

Appends the given path extension to the URL string.

Declared In

NSString+Extensions.h

– urlStringByAppendingPathComponent:

Appends the given path component to the URL string.

- (nonnull NSString *)urlStringByAppendingPathComponent:(nonnull NSString *)pathComponent

Parameters

pathComponent

The path component to append.

Return Value

The resulting URL string.

Discussion

Appends the given path component to the URL string.

Declared In

NSString+Extensions.h

  stringByEncodingUnicodeLiterals

Encodes the unicode literals in the string to hex.

@property (nonatomic, readonly, nonnull) NSString *stringByEncodingUnicodeLiterals

Discussion

Encodes the unicode literals in the string to hex.

Declared In

NSString+Extensions.h

– endsWith:caseSensitive:

Determines whether the string ends with the given string.

- (BOOL)endsWith:(nonnull NSString *)str caseSensitive:(BOOL)caseSensitive

Parameters

str

The end string to check for.

caseSensitive

Whether or not the comparison should be case sensitive.

Return Value

Whether or not the end string was found.

Discussion

Determines whether the string ends with the given string.

Declared In

NSString+Extensions.h

– endsWith:

Determines whether the string ends with the given string. The check is case sensitive.

- (BOOL)endsWith:(nonnull NSString *)str

Parameters

str

The end string to check for.

Return Value

Whether or not the end string was found.

Discussion

Determines whether the string ends with the given string. The check is case sensitive.

Declared In

NSString+Extensions.h

– beginsWith:caseSensitive:

Determines whether the string begins with the given string.

- (BOOL)beginsWith:(nonnull NSString *)str caseSensitive:(BOOL)caseSensitive

Parameters

str

The beginning string to check for.

caseSensitive

Whether or not the comparison should be case sensitive.

Return Value

Whether or not the beginning string was found.

Discussion

Determines whether the string begins with the given string.

Declared In

NSString+Extensions.h

– beginsWith:

Determines whether the string begins with the given string. The check is case sensitive.

- (BOOL)beginsWith:(nonnull NSString *)str

Parameters

str

The beginning string to check for.

Return Value

Whether or not the beginning string was found.

Discussion

Determines whether the string begins with the given string. The check is case sensitive.

Declared In

NSString+Extensions.h

– stringTrimmedFromStart:

Trims a given number of characters from the start of the string.

- (nonnull NSString *)stringTrimmedFromStart:(NSUInteger)numChars

Parameters

numChars

The number of characters to trim.

Return Value

The trimmed NSString object.

Discussion

Trims a given number of characters from the start of the string.

Declared In

NSString+Extensions.h

– stringTrimmedFromEnd:

Trims a given number of characters from the end of the string.

- (nonnull NSString *)stringTrimmedFromEnd:(NSUInteger)numChars

Parameters

numChars

The number of characters to trim.

Return Value

The trimmed NSString object.

Discussion

Trims a given number of characters from the end of the string.

Declared In

NSString+Extensions.h

– stringByRemovingStringFromEnd:caseSensitive:

Removes the given string from the end if it exists.

- (nonnull NSString *)stringByRemovingStringFromEnd:(nonnull NSString *)str caseSensitive:(BOOL)caseSensitive

Parameters

str

The string to remove.

caseSensitive

Whether the string match is case sensitive.

Return Value

The new NSString object.

Discussion

Removes the given string from the end if it exists.

Declared In

NSString+Extensions.h

– stringByRemovingStringFromStart:caseSensitive:

Removes the given string from the start if it exists.

- (nonnull NSString *)stringByRemovingStringFromStart:(nonnull NSString *)str caseSensitive:(BOOL)caseSensitive

Parameters

str

The string to remove.

caseSensitive

Whether the string match is case sensitive.

Return Value

The new NSString object.

Discussion

Removes the given string from the start if it exists.

Declared In

NSString+Extensions.h

– isEqualToString:caseSensitive:

Determines whether the given string is equal to this string.

- (BOOL)isEqualToString:(nonnull NSString *)string caseSensitive:(BOOL)caseSensitive

Parameters

string

The string to compare.

caseSensitive

Whether the comparison should be case sensitive.

Return Value

Whether or not the strings match.

Discussion

Determines whether the given string is equal to this string.

Declared In

NSString+Extensions.h

– matches:

Determines whether this string and the string given are the same when trimmed and case insensitive.

- (BOOL)matches:(nullable NSString *)string

Parameters

string

The string to compare.

Return Value

Whether or not the strings match.

Discussion

Determines whether this string and the string given are the same when trimmed and case insensitive.

Declared In

NSString+Extensions.h

– substringFromStart:fromEnd:

Gets a substring with the given number of characters from the start and end of the string. For example, values of 0 will match the whole string.

- (nonnull NSString *)substringFromStart:(NSUInteger)fromStart fromEnd:(NSUInteger)fromEnd

Parameters

fromStart

The number of characters from the start of the string.

fromEnd

The number of characters from the end of the string.

Return Value

The substring NSString object.

Discussion

Gets a substring with the given number of characters from the start and end of the string. For example, values of 0 will match the whole string.

Declared In

NSString+Extensions.h

– substringFromIndex:toIndex:

Gets a substring with the start and end index of the range.

- (nonnull NSString *)substringFromIndex:(NSUInteger)fromIndex toIndex:(NSUInteger)toIndex

Parameters

fromIndex

The index at the start of the substring.

toIndex

The index at the end of the substring.

Return Value

The substring NSString object.

Discussion

Gets a substring with the start and end index of the range.

Declared In

NSString+Extensions.h

– tabbedStringWithLevel:

Tabs the string to the given level taking into account newlines.

- (nonnull NSString *)tabbedStringWithLevel:(int)level

Parameters

level

The level of indentation to tab.

Return Value

The tabbed NSString object.

Discussion

Tabs the string to the given level taking into account newlines.

Declared In

NSString+Extensions.h

  tabbedString

An indented copy of the string.

@property (nonatomic, readonly, nonnull) NSString *tabbedString

Discussion

An indented copy of the string.

Declared In

NSString+Extensions.h

  utf8DataValue

A UTF-8 encoded NSData copy of the string.

@property (nonatomic, readonly, nonnull) NSData *utf8DataValue

Discussion

A UTF-8 encoded NSData copy of the string.

Declared In

NSString+Extensions.h

  trimmedString

A trimmed copy of the string.

@property (nonatomic, readonly, nonnull) NSString *trimmedString

Discussion

A trimmed copy of the string.

Declared In

NSString+Extensions.h

– containsString:

Determines whether or not the given string exists within this string.

- (BOOL)containsString:(nonnull NSString *)string

Parameters

string

The string to match.

Return Value

Whether or not the string was matched.

Discussion

Determines whether or not the given string exists within this string.

Declared In

NSString+Extensions.h

  randomCharacter

Gets a random character from the string.

@property (nonatomic, readonly) unichar randomCharacter

Discussion

Gets a random character from the string.

Declared In

NSString+Extensions.h

+ stringByRepeatingString:numberOfTimes:separator:

Repeats the given string by the given number of times with the given separator inbetween occurances.

+ (nonnull NSString *)stringByRepeatingString:(nonnull NSString *)string numberOfTimes:(NSUInteger)numberOfTimes separator:(nonnull NSString *)separator

Parameters

string

The string to repeat.

numberOfTimes

The number of times to repeat the string.

separator

The separator to use between occurances of the string.

Return Value

The new NSString object.

Discussion

Repeats the given string by the given number of times with the given separator inbetween occurances.

Declared In

NSString+Extensions.h

  CFStringRef

Returns the underlying bridged CFStringRef reference of this string.

@property (nonatomic, readonly, nonnull) CFStringRef

Discussion

Returns the underlying bridged CFStringRef reference of this string.

Declared In

NSString+Extensions.h

  stringWithUppercaseFirstLetter

Capitalises the first letter of the string.

@property (nonatomic, readonly, nonnull) NSString *stringWithUppercaseFirstLetter

Discussion

Capitalises the first letter of the string.

Declared In

NSString+Extensions.h

  stringWithLowercaseFirstLetter

Lowercases the first letter of the string.

@property (nonatomic, readonly, nonnull) NSString *stringWithLowercaseFirstLetter

Discussion

Lowercases the first letter of the string.

Declared In

NSString+Extensions.h

  MD5Hash

An MD5 hash of the string.

@property (nonatomic, readonly, nonnull) NSString *MD5Hash

Discussion

An MD5 hash of the string.

Declared In

NSString+Extensions.h

  base64String

A base-64 encoded version of the string.

@property (nonatomic, readonly, nonnull) NSString *base64String

Discussion

A base-64 encoded version of the string.

Declared In

NSString+Extensions.h

  urlEncodedString

A URL-encoded version of the string.

@property (nonatomic, readonly, nonnull) NSString *urlEncodedString

Discussion

A URL-encoded version of the string.

Declared In

NSString+Extensions.h

  urlDecodedString

A URL-decoded version of the string.

@property (nonatomic, readonly, nonnull) NSString *urlDecodedString

Discussion

A URL-decoded version of the string.

Declared In

NSString+Extensions.h

  isLocalUrlSchema

Whether or not the URL string is for the local filesystem.

@property (nonatomic, readonly) BOOL isLocalUrlSchema

Discussion

Whether or not the URL string is for the local filesystem.

Declared In

NSString+Extensions.h

  protocolComponent

The protocol component of the string. e.g. http://

@property (nonatomic, readonly, nullable) NSString *protocolComponent

Discussion

The protocol component of the string. e.g. http://

Declared In

NSString+Extensions.h

  protocolString

The protocol of the URL string. e.g. http

@property (nonatomic, readonly, nullable) NSString *protocolString

Discussion

The protocol of the URL string. e.g. http

Declared In

NSString+Extensions.h

  stringByRemovingProtocolString

Removes the protocol component of the string. e.g. www.google.com (removing http://).

@property (nonatomic, readonly, nonnull) NSString *stringByRemovingProtocolString

Discussion

Removes the protocol component of the string. e.g. www.google.com (removing http://).

Declared In

NSString+Extensions.h

– componentsSeparatedByCharactersInSet:trim:removeBlanks:

Splits the string into parts.

- (nonnull NSArray<NSString*> *)componentsSeparatedByCharactersInSet:(nonnull NSCharacterSet *)separator trim:(BOOL)trim removeBlanks:(BOOL)removeBlanks

Parameters

separator

The separator string with which to split.

trim

Whether or not to trim the components.

removeBlanks

Whether or not to remove empty components.

Return Value

An NSArray of string components.

Discussion

Splits the string into parts.

Declared In

NSString+Extensions.h

  slug

A slug version of the string.

@property (nonatomic, readonly, nonnull) NSString *slug

Discussion

A slug version of the string.

Declared In

NSString+Extensions.h

– numberOfComponentsWithSeparator:

Gets the number of components in the string with the given separator character.

- (NSUInteger)numberOfComponentsWithSeparator:(unichar)separatorCharacter

Parameters

separatorCharacter

The separator character.

Return Value

The resulting number of components.

Discussion

Gets the number of components in the string with the given separator character.

Declared In

NSString+Extensions.h

– stringByExtractingComponentsInRange:withSeparator:

Extracts the components in the range given from the string using the given separator character.

- (nonnull NSString *)stringByExtractingComponentsInRange:(NSRange)range withSeparator:(unichar)separatorCharacter

Parameters

range

The range of components to extract.

separatorCharacter

The separator character.

Return Value

The resulting string of components.

Discussion

Extracts the components in the range given from the string using the given separator character.

Declared In

NSString+Extensions.h

– stringByRemovingFirstComponentWithSeparator:

Removes the first components from the string using the given separator character.

- (nonnull NSString *)stringByRemovingFirstComponentWithSeparator:(unichar)separatorCharacter

Parameters

separatorCharacter

The separator character.

Return Value

The resulting string.

Discussion

Removes the first components from the string using the given separator character.

Declared In

NSString+Extensions.h

– stringByRemovingLastComponentWithSeparator:

Removes the last component from the string using the given separator character.

- (nonnull NSString *)stringByRemovingLastComponentWithSeparator:(unichar)separatorCharacter

Parameters

separatorCharacter

The separator character.

Return Value

The resulting string.

Discussion

Removes the last component from the string using the given separator character.

Declared In

NSString+Extensions.h

– lastComponentWithSeparator:

Extracts the last component from the string using the given separator character.

- (nonnull NSString *)lastComponentWithSeparator:(unichar)separatorCharacter

Parameters

separatorCharacter

The separator character.

Return Value

The resulting component.

Discussion

Extracts the last component from the string using the given separator character.

Declared In

NSString+Extensions.h

– stringByAppendingComponent:withSeparator:

Adds a component to the string with the given separator character.

- (nonnull NSString *)stringByAppendingComponent:(nonnull NSString *)componentString withSeparator:(unichar)separatorCharacter

Parameters

componentString

The component string to append.

separatorCharacter

The separator character.

Return Value

The resulting string.

Discussion

Adds a component to the string with the given separator character.

Declared In

NSString+Extensions.h