NSString Base 2-judge prefix, suffix, split, intercept, splice, query

Source: Internet
Author: User

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

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.