I have a filename like this WO.NO 193 AND TASK NO 15146.JPG. I want to split out the extension from the filename. Can someone tell how could i do this with NSSCanner, is there any other way than using the scanner. If so please let me know the solution.
Asked
Active
Viewed 303 times
0
-
you want to separate extension using scanner only no need altrnative method? – Balu May 02 '13 at 12:20
2 Answers
0
i don't know exactly is it correct way or not but it gives the correct value try once,
NSString* str=@"WONO 193 AND TASK NO 15146.JPG";
NSArray *array=[str componentsSeparatedByString:@"."];
str=[str substringToIndex:[str length]-([[array lastObject] length]+1)];
NSLog(@"%@",str);

Balu
- 8,470
- 2
- 24
- 41
0
There are methods in NSString
that do exactly that:
NSString *fn = @"WO.NO 193 AND TASK NO 15146.JPG";
NSString *basename = [fn stringByDeletingPathExtension];
NSString *extension= [fn pathExtension];
So no need to use a scanner, unless you also have other requirements.

Monolo
- 18,205
- 17
- 69
- 103