Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pull an integer value from NSRange?

I have an NSRange and need to break a string into two substrings on either side of this NSRange. How do I get an integer value (like the index) out of an NSRange?

like image 887
user1486548 Avatar asked Aug 27 '12 14:08

user1486548


1 Answers

NSRange struct consists of two integers - the location and the length.

typedef struct _NSRange {
    NSUInteger location;
    NSUInteger length;
} NSRange;

It looks like location and location+length are the two expressions that you are looking for - the ranges for the left and right substring are as follows:

NSRange prefixRange = NSMakeRange(0, myRange.location);
NSUInteger pos =myRange.location+myRange.length;
NSRange suffixRange = NSMakeRange(pos, myString.length - pos);
like image 151
Sergey Kalinichenko Avatar answered Oct 27 '22 09:10

Sergey Kalinichenko