Search code examples
objective-cnsstringnsscanner

NSScanner scan a string from end


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.


Solution

  • 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.