Quote:
Originally Posted by emergination
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:@""];
-
-
-