Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

objective c getting substring after and before dot

i have a string like 112.1 or 102.2 etc now i want to get the substring before dot and after the dot using objective c, means i want to get 2 substrings like this 112 and 1. please guide. Regards Saad.

like image 466
Saad Umar Avatar asked May 28 '12 07:05

Saad Umar


2 Answers

Try the following:

NSArray *arrayWithTwoStrings = [yourString componentsSeparatedByString:@"."];

Using this method you'll get NSArray containing string components that were separated by "." string, that is "112" and "1" for "112.1" string. After that you can access them using array's objectAtIndex: method.

P.S. Note also that if you're going to use numeric values of those strings there might be better solution

like image 133
Vladimir Avatar answered Nov 11 '22 00:11

Vladimir


NSString *str = yourstr;  
NSArray *Array = [str componentsSeparatedByString:@"."];        
NSString *t = [Array objectAtIndex:0];  
NSString *t1 = [Array objectAtindex:1]; 
like image 12
iOS Developer Avatar answered Nov 11 '22 00:11

iOS Developer