#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