Common parsing of IOS NSString APIs

Source: Internet
Author: User

1. Create a constant string.

NSString *astring = @ "This is a string!";

2, create an empty string, give the assignment.

NSString *astring = [[NSString alloc] init]; Astring = @ "This is a 59wan.cn website!"; [Astring release]; NSLog (@ "astring:%@", astring);//nsstring *astring = [[NSString alloc] init]; NSLog (@ "0x%.8x", astring); [Email protected] "This is a string!"; NSLog (@ "0x%.8x", astring); [Astring release]; NSLog (@ "astring:%@", astring);

3, in the above method, lifting speed: Initwithstring method

NSString *astring = [[NSString alloc] initwithstring:@ "This is a string!"]; NSLog (@ "astring:%@", astring); [Astring release];

4. Create a string with standard C: Initwithcstring method

*cstring =; NSString *astring = [[NSString alloc] initwithcstring:cstring]; NSLog (, astring); [Astring release];

5. Create a formatted string: placeholder (composed of one% plus one character)

i =; j =; NSString *astring = [[NSString alloc] initwithstring:[nsstring Stringwithformat:,i,j]]; NSLog (, astring); [Astring release];


6. Create a temporary string

NSString *astring; astring = [NSString stringwithcstring:]; NSLog (, astring);






This article is from the "cocos2d-x" blog, make sure to keep this source http://lonag.blog.51cto.com/3340984/1630170

Common parsing of IOS NSString APIs

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.