objective c - How to extract two numbers from an NSString? -


below string have

nsstring *mystring = @"file_1_23.pdf";                             ^ ^^ 

what want extract 1 & 23.

any idea how this?

other possible of string can

nsstring *mystring = @"file_12_2.pdf"; nsstring *mystring = @"file_123_8.pdf"; 

i believe need use method - (nsstring *)substringwithrange:(nsrange)range;, confused on how second index of _

format string

file_anynumber_anynumber.fileextension 

note: have _ 2 times , making me crazy.

this break components of string array of strings.

nsstring *mystring = @"file_123_8.pdf";  nscharacterset *delimiters = [nscharacterset charactersetwithcharactersinstring:@"_."]; nsarray *components = [mystring componentsseparatedbycharactersinset:delimiters]; 

now components array contains string-objects @"file", @"123", @"8", @"pdf"


Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -