Nsmakerange,substringwithrange,substringtoindex,substringfromindex Differences and linkages

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.