OC String NSString Common Operation series 01

Source: Internet
Author: User

    • OC String Common Operations
    1. NSString Basic Operation
1 /**2 * NSString string Common operations3 * Initwithformat: Construction method4 * initwithutf8string: Convert C string to OC string5  */6 #import<Foundation/Foundation.h>7 8 intMainintargcConst Char*argv[]) {9 @autoreleasepool {Ten          One         Char*str1="Hello str1";//C language String ANSLog (@"%s", str1);//Print Result: Hello str1 -          -NSString *str2=@"Hello str2";//the string in OC theNSLog (@"%@", str2);//Print Result: Hello str2 -          -         //Initwith ... Construction Method -NSString *str3=[[nsstring Alloc]initwithformat:@"Hello STR3"]; +NSLog (@"%@", STR3);//Print Result: Hello str3 -          +         //Initwithformat ... Formatting strings ANSString *str4=[[nsstring Alloc]initwithformat:@"I am the first%d string STR4",4]; atNSLog (@"%@", STR4);//I am the 4th string of STR4 -          -         //Converting a C-language string to an OC string -NSString *str5=[[nsstring alloc]initwithutf8string:"Hello STR5"]; -NSLog (@"%@", STR5);//Print Result: Hello STR5 -      in     } -     return 0; to}


OC String nsstring common operation series

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.