How to create a string (OC)

Source: Internet
Author: User

String class: NSString The length of the object created and cannot be changed

Create string (first) (most commonly used)

NSString *string1 = @ "iphone";

Create a string (the second type)

NSString *string2 = [[NSString alloc]initwithstring: string1];

NSLog (@ "%@", string2);

NSString.h how to appear always press cmd and click on it.

The third kind is not used

NSString *string3 = [NSString string]; Create an empty string with the convenience constructor method

NSLog (@ "%@", string3);

The fourth kind is not used

NSString *string4 = [NSString stringwithstring: string1];

NSLog (@ "%@", String4);

Fifth type

[[NSString alloc]initwithstring:<# (NSString *) #>]

NSString *string5 = [[NSString alloc]initwithformat: @ "%@%@", string1,

STRING2]; Can pass multiple parameters, this must be remembered.

NSLog (@ "%@", string5);

The sixth type (most commonly used

NSString *string6 = [NSString stringwithformat:@ "%@%@", string1,string2];

NSLog (@ "%@", String6);

How to create a string (OC)

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.