Tag Archives: NSString

Email id verification using Objective C

By | March 29, 2011

Hi, In order to verify an email address you have entered is valid or not using Objective C, use the following code. – (BOOL) checkYourMail: (NSString *) myEmail{ NSString *checkMail= @”[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+.[A-Za-z]{2,4}”; NSPredicate *matchMail = [NSPredicate predicateWithFormat:@”Matching %@”, checkMail]; return [matchMail evaluateWithObject:myEmail]; } 🙂

Splitting a string using symbols in Objective C

By | March 20, 2011

Hi, If you want to split a string between a symbol like, ‘.’ or ‘-‘ or ‘,’ in Objective C, what to do? See the code for how to split string in Objective C. NSString *myString = @”song.mp3”; NSArray *splitArray = [myString componentsSeparatedByString:@”.”]; This code will split the string ‘myString’ into ‘song’ & ‘mp3’ (separated… Read More »

Adding Image to a UIImageView using Image URL

By | March 14, 2011

Hi, Sometimes you need to add Image to a UIImageView from the URL of the image you got. In that case, this is how you can add image to the UIImageView. NSString *picURL= @”http://photobucket.com/yourImage.gif”; NSData *picData = [[NSData alloc]initWithContentsOfURL:[NSURL URLWithString:mapURL]]; UIImage* picture = [[UIImage alloc] initWithData:picData]; [pictureView setImage:picture]; [picData release]; [picture release]; Here, pictureView is… Read More »

Delete a substring in Objective C, Iphone , Mac………….

By | March 10, 2011

This code snippet deletes a substring from a original string.. /** initialize two strings **/ NSString *string = @”This is heaven”; NSString *part = @”heaven”; /** Get the range of the substring in the original string **/ NSRange range = [string rangeOfString:part]; /** Delete the substring from the original string **/ [string deleteCharactersInRange:range]; Please leave… Read More »

How to add infinite backgrounds in Cocos2D, iphone?

By | December 24, 2010

You often may need scrolling backgrounds in your game or any other application. The following code helps you to add continuous backgrounds. Each sprite is added to the right of the current sprite which make them continuos. //Add more stripes, flip them, and position them next to their neighbour stripe. for (int i = 0;… Read More »

Working with files in Objective C

By | December 22, 2010

Basic file operations Assumes the existence of a file called “testfile” in the current working directory #import #import #import #import #import int main (int argc, char *argv[]) { NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; NSString *fName = @”testfile”; NSFileManager *fm; NSDictionary *attr; // Need to create an instance of the file manager fm =… Read More »

How to use picker in iphone, A simple example.

By | December 20, 2010

#import “ViewController.h” @implementation ViewController @synthesize mlabel; – (void)viewDidLoad { [super viewDidLoad]; arrayNo = [[NSMutableArray alloc] init]; [arrayNo addObject:@” Hello “]; [arrayNo addObject:@” Hai “]; [arrayNo addObject:@” Picker “]; [arrayNo addObject:@” Simple “]; [arrayNo addObject:@” example “]; [pickerView selectRow:1 inComponent:0 animated:NO]; mlabel.text= [arrayNo objectAtIndex:[pickerView selectedRowInComponent:0]]; } – (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView; { return 1; } – (void)pickerView:(UIPickerView *)pickerView… Read More »