[Study Notes] [OC language] NSString, ocnsstring

Source: Internet
Author: User

[Study Notes] [OC language] NSString, ocnsstring

1. Fast creation of strings
NSStirng * str = @ "Hello ";

2. Create using static methods

3. Use % @ to output the string
NSString * name = @ "dssf ";
NSLog (@ "My name is % @", name );

4. Code

1 # import <Foundation/Foundation. h> 2 3 @ interface Person: NSObject 4 {5 // char * _ name; 6 NSString * _ name; 7} 8 @ end 9 10 int main () 11 {12/* 13 // The simplest way to create a string 14 NSString * str = @ "isdssf"; 15 16 char * name = "isdssf "; 17 18 19 NSLog (@ "my classes at % @", str); 20 // NSLog (@ "% s", name ); 21 */22 23 int age = 15; 24 int no = 5; 25 NSString * name = @ "Haha jan "; 26 // The length method calculates the number of characters 27 int size = [name length]; 28 29 NSLog (@ "% d", size ); 30 31 // create an OC string in another way 32 NSString * newStr = [NSString stringWithFormat: @ "My age is % d and no is % d and name is % @", age, no, name]; 33 34 35 NSLog (@ "---- % ld", [newStr length]); 36 37 return 0; 38}

 

 

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.