Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Mockup & CodeGen, iPhone & iPad
($9.99)

Make your own iPhone apps
and run them live!
(free)

Manu
($0.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > Mac OS X Development Forums > Objective-C, Python, Ruby Development

Reply
 
LinkBack Thread Tools Display Modes
Old 04-09-2009, 07:14 AM   #1 (permalink)
New Member
 
Join Date: Apr 2009
Posts: 3
Red face Checking NSString for numbers and substrings?

I'm new to iPhone development and Objective-C. I'm sure you get a lot of that here.

Anyway, I need to do a couple checks on a string. First I need to make sure there aren't any numbers in it. Then I need to make sure it doesn't contain a few substrings ('jpg', 'gif', 'png'). It looks like rangeOfString is what I want, but I'm not comfortable with Objective-C yet and I was hoping somebody could show me the best way to do this.

Thanks!
emergination is offline   Reply With Quote
Old 04-23-2009, 08:47 AM   #2 (permalink)
Reena
 
Join Date: Apr 2009
Posts: 31
Default

Quote:
Originally Posted by emergination View Post
I'm new to iPhone development and Objective-C. I'm sure you get a lot of that here.

Anyway, I need to do a couple checks on a string. First I need to make sure there aren't any numbers in it. Then I need to make sure it doesn't contain a few substrings ('jpg', 'gif', 'png'). It looks like rangeOfString is what I want, but I'm not comfortable with Objective-C yet and I was hoping somebody could show me the best way to do this.

Thanks!

try this ,

NSString *str=@"abcd12efg9.jpg.png"; //GIVE YOUR STRING TO CHECK
//TO CHECK DIGIT 0 TO 9
for(int i=0;i<10;i++)
{
NSRange rng = [str rangeOfString:[NSString stringWithFormat:@"%d",i]];
if(rng.length > 0)
{
str = [str stringByReplacingOccurrencesOfString:[NSString stringWithFormat:@"%d",i] withString:@""];
}
}

//TO REMOVE FEW WORDS
str = [str stringByReplacingOccurrencesOfString:@".jpg" withString:@""];
str = [str stringByReplacingOccurrencesOfString:@".gif" withString:@""];
str = [str stringByReplacingOccurrencesOfString:@".png" withString:@""];
-
-
-
reena is offline   Reply With Quote
Reply

Bookmarks

Tags
iphone, nsstring, objective-c, rangeofstring, substring

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 243
13 members and 230 guests
ADY, CKAmike, Dani77, dessicant, Duncan C, HemiMG, nick.keroulis, Promo Dispenser, Punkjumper, Rudy, sacha1996, sneaky, spiderguy84
Most users ever online was 1,187, 10-11-2011 at 08:09 AM.
» Stats
Members: 158,885
Threads: 89,231
Posts: 380,768
Top Poster: BrianSlick (7,129)
Welcome to our newest member, bookesp
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 03:22 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0