Dark Horse programmer--"Dark Horse video note" OC Language Foundation NSString

Source: Internet
Author: User

      1. Creation of strings
         1:  @ "Jack";
         2:      
         3:      //nsstring *s2 = [[NSString alloc] initwithstring:@ "Jack"];
         4:      
         5:      nsstring *s3 = [[NSString alloc] Initwithformat:@ "Age is%d", 10];
         6:      
         7:      //C string > C string
        Ten:      constchar *cs = [S4 utf8string];
        11:      
      Nsutf8stringencoding   :      //Use this code in Chinese
        :      nsstring *s5 = [[NSString alloc] Initwithcontentsoffile:@ "/users/apple/desktop /1.txt " encoding:nsutf8stringencoding Error:nil];
        14:      

         1:  /*
         2:        There will always be a class method paired with the object method
         3:       [Nsurl urlwithstring:<# (NSString *) #>];
         4:       [NSString stringwithformat:@ ""];
         5:       [NSString stringwithcontentsoffile:<# (NSString *) #> encoding:<# ( nsstringencoding) #> error:<# (nserror *__autoreleasing *) #>];
         6:       
         7:       * /

      2. Common methods

      1) Check the prefix

         1:  @ "Qq=12344&pwd=adadfs";
         2:      [str hasprefix:@ "qq="];
         3:      
         4:      [str hassuffix:@ "FS"];

      2) uppercase and lowercase conversions

         1:      nsstring *str = [@ "Adbdad" lowercasestring];
         2:      nsstring *upstr = [str uppercasestring];
         3:      NSLog (@ "%@", UPSTR);
         4:      //    [[@ "Adbdad" lowercasestring] isequaltostring:@ "ADSFASD" ];

      3) Variable string

         1:     nsmutablestring *str = [[Nsmutablestring alloc] initwithcapacity:0];
         2:      
         3:      [str appendformat:@ "123"];  //123
         4:      //    NSLog (@ "%@", str);
         5:      //
         6:      //    NSString *str1 = @ "123";
         7:      //    NSString *str2 = [str1 stringbyappendingstring:@ "AAAA"];
         8:      //    NSLog (@ "%@", str2);
         9:      //
        :      nsrange rang3 = [str rangeofstring:@ "3"];
      One   :      [str deletecharactersinrange:rang3];
        :      NSLog (@ "%@", str);
        13:      
        :      [str insertstring:@ "AAA" atindex:0];
        15:      
      +   :      //@ "3" @ ""
      +   :      [str replaceoccurrencesofstring:@ "3"
        :                           withstring:@ ""
        :                              Options:nsliteralsearch
        :                                range:nsmakerange (0, str.length)];
        :      NSLog (@ "%@", str);

      Dark Horse programmer--"Dark Horse video note" OC Language Foundation NSString

      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.