typedef nsrange *nsrangepointer;
ns_inline nsrange nsmakerange (Nsuinteger Loc, Nsuinteger len) {
Nsrange R;
r.location = loc;
r.length = len;
return R;
}
Nsmakerange is a struct type that contains two parameters, position, and length. Represents the position and length of the string to be passed in from where it was started.
Substringwithrange need to pass in the Nsrange type, indicating where to start the interception and length, and return the string type. For example, nsstring *bankcardstring = [Respdict objectforkey:kqftrackdata];
Nsrange Bankrang = Nsmakerange (0, 3);
nsstring *bankstr1 = [bankcardstring Substringwithrange:bankrang];
Substringtoindex represents the start of the intercept from the first string, to the specified length position, but does not include the position string at the specified position, such as nsstring *balancedatestring = [Respdict objectforkey:k Qftime];
nsstring *ymdstring = [balancedatestring substringtoindex:10];
//And then intercept from the existing string
//year
nsstring *yearstr = [ymdstring substringtoindex:4];
The Substringfromindex indicates that the string is truncated from the specified position to the last, and the location contained at the specified location.
Nsrange Monthrang = Nsmakerange (5, 2);
nsstring *monthstr = [ymdstring Substringwithrange:monthrang];
//day
nsstring *daystr = [ymdstring substringfromindex:8];
Nsmakerange,substringwithrange,substringtoindex,substringfromindex Differences and linkages