Strings - Objective C
The string in Objective C programming language is represented using NSString and its subclass NSMutableString provides ways for creating string objects. The simplest way to create a string object is to use the Objective C @".." construct:
NSString *greeting = @Hello";
A simple example for creating and printing a string is shown below:
#import <Foundation/Foundation.h>
int main()
{
NSString *greeting = @Hello";
NSLog(@"Greeting message: %@\n", greeting );
return 0;
}
int main()
{
NSString *greeting = @Hello";
NSLog(@"Greeting message: %@\n", greeting );
return 0;
}
S.N. | Method and purpose |
---|---|
1 | -(NSString *)capitalizedString; Returns a capitalized representation of the receiver. |
2 | -(unsigned)characterAtIndex : (NSUInteger)index; Return the character at a given array position. |
3 | -(double)doubleValue; Return the floating-point value the receiver's text as a double. |
4 | -(float)floatValue; Return the floating-point value of the receiver's text as a float. |
5 | -(BOOL)hasPrefix : (NSString *)aString; Return a boolean value that indicates whether a given string matches the begining characters of the receiver. |
6 | -(BOOL)hasSuffix : (NSString *)aString; Return a boolean value that indicates whether a given string matches the ending characters of the receiver. |
7 | -(NSInteger)integerValue; Return the NSInteger value of the reciver's text. |
8 | -(id)initWithFormat : (NSString *)format...; Return an NSString object initialized by using a given format string as a template into which the remaining argument values are substituted. |
9 | -(BOOL)isEqualToString : (NSString *)aStringl return a boolean value that indicate whether a given string is equal to the reciver using a literal unicode-based comparison. |
10 | -(NSUInteger)length; Return the number of unicode character in the receiver. |
11 | -(NSString *)lowercaseString; Return lowercae representation of the receiver/ |
12 | -(NSRange)rangeOfString : (NSString *)aString; Finds and return the range of the first occurence of a given string within the receiver. |
13 | -(NSString *)stringByAppendingFormat : (NSString *)foramt..; Return a string made by appending to the receiver a string constructed from a given format string and the following argument. |
14 | -(NSString *)stringByTrimmingCharactersinSet : (NSCharacterSet *)set; Return a new string made by removing from both ends of the receive characters contained in a given character set. |
15 | -(NSString *)substringFromIndex : (NSUInteger)atIndex; Return a new string containing the characters of the receiver from the one at a given index to the end. |
Following example makes use of few of the above mentioned functions:
No comments: