Instance Method

stringByTrimmingCharactersInSet:

Returns a new string made by removing from both ends of the receiver characters contained in a given character set.

Declaration

- (NSString *)stringByTrimmingCharactersInSet:(NSCharacterSet *)set;

Parameters

set

A character set containing the characters to remove from the receiver. set must not be nil.

Return Value

A new string made by removing from both ends of the receiver characters contained in set. If the receiver is composed entirely of characters from set, the empty string is returned.

Discussion

Use whitespaceCharacterSet or whitespaceAndNewlineCharacterSet to remove whitespace around strings.

See Also

Dividing Strings

- componentsSeparatedByString:

Returns an array containing substrings from the receiver that have been divided by a given separator.

- componentsSeparatedByCharactersInSet:

Returns an array containing substrings from the receiver that have been divided by characters in a given set.

- substringFromIndex:

Returns a new string containing the characters of the receiver from the one at a given index to the end.

- substringWithRange:

Returns a string object containing the characters of the receiver that lie within a given range.

- substringToIndex:

Returns a new string containing the characters of the receiver up to, but not including, the one at a given index.