1 #import<Foundation/Foundation.h>2 3 intMainintargcConst Char*argv[]) {4 @autoreleasepool {5 //Judging string prefixes6NSString *str1=@"Ios-study";7BOOL result1=[str1 Hasprefix:@"IOS"];8 //To determine a string suffix9NSString *str2=@"study.jpg";TenBOOL result2=[str2 Hassuffix:@". jpg"]; One //Split String ANSString *str3=@"I am a new programmer"; -Nsarray *ARRAY=[STR3 componentsseparatedbystring:@" "];//split based on a given character -NSLog (@"%@", array);//Direct printing of arrays (generally not allowed in formal programs) the //Intercept String -NSString *STR4=[STR3 Substringtoindex:4];//before the string starts to intercept to the 4th bit -NSString *STR5=[STR3 Substringfromindex:4];//Intercept from 4th bit to the bottom of the string - //intercept strings based on location and intercept length + Nsrange rang1; -rang1.location=7; +Rang1.length=3; ANSString *STR6=[STR3 Substringwithrange:rang1];//3 characters starting from 7th bit according to rang atNsrange RANG2=[STR3 rangeofstring:@"Programmer"];//get the starting position and length of a string - //Stitching Strings -NSString *str7=@"Good", *str8=@"Bye"; -NSString *str9=[[nsstring Alloc]initwithformat:@"%@%@", STR7,STR8];//instance initialization method splicing -NSString *STR10=[STR7 STRINGBYAPPENDINGSTRING:STR8];//Direct Stitching -NSString *STR11=[STR7 Stringbyappendingformat:@"-%@", Str8];//add other characters to the stitching in //query string -Nsrange RANG3=[STR3 rangeofstring:@"New"];//the location of the query string toNSLog (@"%@", Nsstringfromrange (Rang3));//show where the string is located + if(rang3.location==nsnotfound) { -NSLog (@"Can ' t find"); the } * Else{ $NSLog (@"location=%ld,length=%ld", rang3.location,rang3.length);Panax Notoginseng } - } the return 0; +}
NSString Base 2-judge prefix, suffix, split, intercept, splice, query