Goal c getting the substring after and to the point

I have a line like 112.1 or 102.2 etc. Now I want to get a substring in front of and after a dot using lens c, which means I want to get 2 substrings of type 112 and 1. please refer. Regards, Saad.

+5
source share
3 answers

Try the following:

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

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

PS Also note that if you intend to use the numerical values โ€‹โ€‹of these strings, there may be a better solution.

+20
source
NSString *str = yourstr;  
NSArray *Array = [str componentsSeparatedByString:@"."];        
NSString *t = [Array objectAtIndex:0];  
NSString *t1 = [Array objectAtindex:1]; 
+8
source
NSArray* components = [yourString componentsSeparatedByString:@"."];
+1
source

All Articles