I have a string coming from server. I am identifying a particular substring and then breaking the main string at that substring.
NSString *string = /* getting from server */;
NSString *strAddress = /* Substring of string */;
NSArray *arr = [string componentsSeparatedByString:strAddress];
NSString *strBeforeAddress = [arr objectAtIndex:0];
This works perfectly fine when strAddress has something before it. But in some cases it completely gives a strange result. For example, when
string = @"cxzcvxcv\n14, Beaven Dam Road\nVail, CO81657";
strAddress = @"14, Beaven Dam Road\nVail, CO81657";
I get only one object in arr, the complete string, which I think is wrong. It should give result as 2 objects: cxzcvxcv and blank object. However, when
string = @"14, Beaven Dam Road\nVail, CO81657";
strAddress = @"14, Beaven Dam Road\nVail, CO81657";
the array arr in this case has 1 object, the complete string. Can someone please explain what is going on here?
If
Then
strBeforeAddresswill be –cxzcvxcv\nIf
then
strBeforeAddresswill benil.