Find its exact location and length based on the specific information in the string

Source: Internet
Author: User

#import <Foundation/Foundation.h>

int main (int argc, const char * argv[]) {

@autoreleasepool {

/* nsstring *[email protected] "Apple banana pear";

Nsarray *array=[str componentsseparatedbystring:@ ""];

NSLog (@ "%@", array); */

/*//substringtoindex from the beginning of the string to the location you specified, but not the location you specified

NSString *[email protected] "ABCDEFG";

NSString *newstr1=[str1 Substringtoindex:4];

NSLog (@ "%@", NEWSTR1);

Substringfromindex all characters starting at the specified position (and including the specified position)

NSString *newstr2=[str1 Substringfromindex:4];

NSLog (@ "%@", NEWSTR2); */

/*//intercept string by range

NSString *[email protected] "ABCDEFG";

Nsrange rang;

rang.location=2;

rang.length=3;

NSString *NEWSTR3=[STR3 Substringwithrange:rang];

NSLog (@ "%@", NEWSTR3); */

NSString *[email protected] "http://localhost:8099/test/user=admin&pwd=123";

Nsrange rang= [String rangeofstring:@ "pwd="];

NSLog (@ "Location=%ld,length=%ld", rang.location,rang.length);

NSLog (@ "pwd=%@", [string substringfromindex:rang.location+rang.length]);

}

return 0;

}

Find its exact location and length based on the specific information in the string

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.