Sunday, May 12, 2013

NSString characterAtIndex example ios


Returns the character at a given array position.
- (unichar)characterAtIndex:(NSUInteger)index
The index of the character to retrieve. The index value must not lie outside the bounds of the receiver.
Return Value of [NSString characterAtIndex]
The character at the array position given by index.
Raises an NSRangeException if index lies beyond the end of the receiver.
Example of [NSString characterAtIndex]
NSString *newString;
if ( [[myString characterAtIndex:0] isEqualToString:@"*"] ) {
     newString = [myString substringFromIndex:1];
Example of [NSString characterAtIndex]
NSString *temp = @"Hello";
NSString *temp2 = @"H";

if([temp characterAtIndex:0] == [temp2 characterAtIndex:0] )
Example of [NSString characterAtIndex]
unichar ch = [self.text characterAtIndex:position];
NSLog(@"%c", ch);

if (ch == '.') {} // single quote around dot, not double quote