Text and Strings - Objective C
NSCharacterSet and NSString
NSString is one the most commonly used classes that is used for storing strings and texts. If you want to know more about NSString please refer NSString in Objective C strings.
As mentioned earlier, NSCharacterSet represents various of character used by the NSString and NSScanner classes.
NSCharacterSet
Here is the set of methods avaiable in NSCharacterSet which represents the various character sets.
In the above program , the punctuations on both sides given strings is trimmed. It's just an example of using NSCharacterSet.
NSString is one the most commonly used classes that is used for storing strings and texts. If you want to know more about NSString please refer NSString in Objective C strings.
As mentioned earlier, NSCharacterSet represents various of character used by the NSString and NSScanner classes.
NSCharacterSet
Here is the set of methods avaiable in NSCharacterSet which represents the various character sets.
- AlphanumericCharacterSet : Return a character set containing the characters in the categories Letters, Marks, and Numbers.
- CapitalizedLetterCharacterSet : Return a character set containing the characters in the category of Titlecase letters.
- characterSetWithCharactersinString : Return a character set containing the characters in a given string.
- characterSetWithRange : Returns a character set containing characters with Unicode values in a given range.
- illegalCharacterSet : Return a character set containing values in the categories of Non-characterSet or that have not yet been defined in version 3.2 of the Unicode standard.
- lettersCharacterSet : Return a character set containing the characters in the categories letters and marks.
- lowercaseLetterCharacterSet : Return a character set containing the characters in the category of lowecase letters.
- newlineCharacterSet : Return a character set containing the newline characters.
- punctuationCharacterSet : Returns a character set containing the characters in the category of punctuation.
- symbolCharacterSet : Returns a character set containing the characters in the category of symbols.
- uppercaseLetterCharacterSet : Return a character set containing the characters in the categories of uppercase letters and titlecase letters.
- whitespaceAndNewlineCharacterSet : Return a character set containing Unicode general category z8 U000A ~ U000D and U0085.
- whitespaceCharacterSet : Return a character set containing only the in-line whitespace characters space (U + 0020) and tav (U + 0009).
#import <Foundation/Foundation.h>
int main()
{
NSString *str = @"....a4droid.....";
NSLog(@"Initial string is %@", str);
NSCharacterSet *characterset = [[NSCharacterSet puntuationCharacterSet];
v str = [str stringByTrimmingCharactersInSet : characterset];
NSLog(@"FInal string is %@", str);
return 0;
}
int main()
{
NSString *str = @"....a4droid.....";
NSLog(@"Initial string is %@", str);
NSCharacterSet *characterset = [[NSCharacterSet puntuationCharacterSet];
v str = [str stringByTrimmingCharactersInSet : characterset];
NSLog(@"FInal string is %@", str);
return 0;
}
In the above program , the punctuations on both sides given strings is trimmed. It's just an example of using NSCharacterSet.
No comments: