To create a string, get the string

Source: Internet
Author: User

#import <FOUNDATION/FOUNDATION.H>//1 the way to create a string int main (int argc, const char * argv[]) {    @autoreleasepool {                     NSString * str = @ "oc str";        NSLog (@ "str%@", str);             char * c = "C str";        char * C1 = "I am a C language string";        NSString * str1 = [[NSString alloc] initwithcstring:c1  encoding:nsutf8stringencoding];        NSLog (@ "str1%@", str1);               int i = ten;        NSString * str2 = [[NSString alloc] initwithformat:@ "format%@%d", str1,i];        NSLog (@ "str2%@", str2);        int year =;        int month =;        int day =;                       NSString * STR3 = [[NSString alloc] initwithformat:@ "%d years%02d month%d days", Year,month,day];        NSLog (@ "%@", STR3);    }    return 0;}
/*1> gets the length of the string 2 > Obtains a single character from the index 3 > gets a substring from the index 4 > The index position of the string in another string based on the string */#import <foundation/foundation.h        >int Main (int argc, const char * argv[]) {@autoreleasepool {NSString * str = @ "Baidu";        Nsuinteger count = [str length];              NSLog (@ "%lu", count);        char c = [Str characteratindex:0];                     NSLog (@ "%d", c);        NSString * substr1 = [str substringfromindex:3];               NSLog (@ "Substr1%@", SUBSTR1);        NSString * substr2 = [str substringtoindex:3];        NSLog (@ "Substr2%@", SUBSTR2);        Nsrange range = {2,3}; /* Nsuinteger location start position nsuinteger length *///Substringwithrange length from Loccation        Characters NSString * SUBSTR3 = [str substringwithrange:range];               NSLog (@ "%@", SUBSTR3);        NSString * str1 = @ "www.baidu.com";              Nsrange range2 = [str1 rangeofstring:str];    NSLog (@ "%@", Nsstringfromrange (Range2)); } return 0;}


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

To create a string, get the string

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.