Common NSString operations,

Source: Internet
Author: User

Common NSString operations,

 

NSString * testStr01 = @ "HelloWord"; NSString * testStr02 = [testStr01 substringToIndex: 5]; // obtain the header (from the beginning ), to does not include the subscript content NSString * testStr03 = [testStr01 substringFromIndex: 5]; // tail (from where to the end), from contains the subscript content NSLog (@ "testStr02: % @ testStr03: % @ ", testStr02, testStr03); nsange r = {4, 3}; // obtain the length of NSString * testStr04 = [testStr01 substringWithRange: r]; NSLog (@ "testStr04: % @", testStr04); // String concatenation NSString * testStr05 = @ "Hello"; // append NSString * testStr06 = [testStr05 stringByAppendingString: @ "World"]; NSLog (@ "testStr06: % @", testStr06); // initialize NSString * testStr07 = @ "Hello"; NSString * testStr08 = @ "World "; NSString * testStr09 = [NSString stringWithFormat: @ "% @", testStr07, testStr08]; NSString * testStr10 = [NSString stringWithFormat: @ "Hello % @", testStr08]; NSLog (@ "testStr09: % @", testStr09); NSLog (@ "testStr10: % @", testStr10); // in the specified format (range) append content NSString * testStr11 = @ "Hello"; NSString * testStr12 = [testStr11 stringByAppendingFormat: @ "% @", @ "World", @ "123"]; NSLog (@ "testStr12: % @", testStr12); // replace NSString * testStr13 = @ "www.kyle.com.cn"; NSString * testStr14 = [testStr13 kernel: NSMakeRange (4, 6) withString: @ "163"]; NSLog (@ "testStr14: % @", testStr14 ); // set of parameters // the path of the parameter file does not include the file name NSString * path = @ "/Users/apple/Desktop"; // path = [path stringByAppendingString: @ "/test.txt"]; path = [path stringByAppendingString: @ "/test. rtf "]; // read the content of the file to a string // NSString * str20 = [[NSString alloc] initWithContentsOfFile: path]; NSString * testStr15 = [[NSString alloc] initWithContentsOfFile: path encoding: NSUTF8StringEncoding error: nil]; NSLog (@ "testStr15: % @", testStr15 ); NSString * use = @ "fcp"; NSString * use1 = @ "fcp"; NSString * password = @ "123"; NSString * password1 = @ "123 "; if ([use isEqualToString: use1] & [password isEqualToString: password1]) {NSLog (@ "Login successful");} else {NSLog (@ "Login Failed ");}

 

Related Article

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.