OBJECTIVE-C Foundation Framework Practice--nsstring (iii) __foundation

Source: Internet
Author: User
#import <Foundation/Foundation.h> int main (int argc, const char * argv[]) {@autoreleasepool {///////// Determine whether two strings are the same; NSString *string1 = @ "Hello worl
    D ";
    BOOL SS = [string1 isequaltostring:@ "A"];
    
    
    NSLog (@ "%HHD", SS);
     The result of the comparison string/* Nscomparisonresult is an enumeration type, enum {nsorderedascending =-1, Nsorderedsame,
     Nsordereddescending};
     
     typedef Nsinteger Nscomparisonresult; Nsorderedascending: The string of coordinates is smaller than the right, -1 Nsorderedsame: the string is equal; 0 nsordereddescending: The string on the left is larger than the right; 1/N
    Scomparisonresult result = [string1 compare:@ "B"];
    
    
    NSLog (@ "Compare String%ld", (long) result);
    Split character split string according to the specified character; NSString *string2 = @ "A,b,c,d,e,f,g";
    
    Nsarray *array = [string2 componentsseparatedbystring:@ ","];
    Iterates through each character in the array; for (NSString *s in array) {NSLog (@ "%@", s); }//FollowRange intercept string; NSString *string3 = @ "ABCDEFGH";
    Nsrange range = Nsmakerange (0, 3);
    
    
    NSString *string4 = [string3 substringwithrange:range];//use range to intercept a string NSLog (@ "String4 =%@", String4);
    To intercept a string from one beginning to the last; NSString *string5 = [String3 substringfromindex:3];
    
    NSLog (@ "string5 =%@", string5);
    Intercept a string from the beginning to a certain person; nsstring *string6 = [String3 substringtoindex:3];
    
    
    NSLog (@ "String6 =%@", string6); Splits the string into each character; for (int i = 0; i < string3.length i++) {//returns a character; NSLog (@ "%c", [string3 character
    ATINDEX:I]);
    //Find NSString *string7 = @ "AB CD ef GH ij KL";
    Finds the position of the specified string; nsrange range2 = [String7 rangeofstring:@ "EF"];
    
    
    NSLog (@ "length =%lu; location =%lu", (unsigned long) range2.length, (unsigned long) range2.location);
    Replace nsstring *string8 = @ "AB CD ef GH ij KL";
   NSString *STRING9 = [String8 stringbyreplacingoccurrencesofstring:@ "gh" withstring:@ "Hello"]; NSLog (@ "STRING9 =%@", STRING9);
    NSString *string10 = [String8 stringbyreplacingcharactersinrange:nsmakerange (3, 2) withstring:@ "IOS"];
    
    
    NSLog (@ "STRING10 =%@", string10);
  return 0; }
}

The output results are as follows:


GitHub home: https://github.com/chenyufeng1991. You are welcome to visit.

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.