OBJECTIVE-C Foundation Framework Practice--nsstring (ii) __objective-c

Source: Internet
Author: User

For NSString, there are many practical methods, such as: case conversion, prefix matching, string concatenation, formatting strings, and so on. Let's take a look at the following:

#import <Foundation/Foundation.h> int main (int argc, const char * argv[]) {@autoreleasepool {char
    *STR1 = "Hello";
    
    
    NSString *STR2 = @ "World";
    
    OC-> C NSLog (@ "oc->c =%s", [str2 utf8string]);
    C-> OC nsstring *s = [NSString stringwithutf8string:str1];
    
    
    
    NSLog (@ "C-&GT;OC =%@", s);
    
    This is no need for us to release the memory; NSString *STR3 = @ "IOS";
    This requires us to release the memory, as long as we are inti; nsstring *STR4 = [[NSString alloc]init];
    
    STR4 = @ "OC";
    format string; int a = 10;
    NSString *STR5 = [[NSString alloc] initwithformat:@ "%d", a];
    
    NSLog (@ "STR5 =%@", STR5);
    Stitching string NSString *STR6 = [Str3 STRINGBYAPPENDINGSTRING:STR4];
    
    
    NSLog (@ "STR6 =%@", STR6);
    Case conversion//uppercase--> lowercase: Regardless of the original character's case, all converted to lowercase; nsstring *str7 = [STR4 lowercasestring];
    
    NSLog (@ "Lower STR4 =%@", STR7);
    lowercase--> Capital NSString *str8 = [Str7 uppercasestring];
  NSLog (@ "Upper STR7 =%@", str8);  
    
    
    The judgement of the prefix nsstring *STR9 = @ "ABCDEFG";
    Here the output of the bool value is formatted with a%hhd,true output of 1,false output 0; bool Hasprefix = [STR9 hasprefix:@ "ABC"];
    
    NSLog (@ "Hasprefix =%HHD", hasprefix);
    BOOL Hassuffix = [STR9 hassuffix:@ "F6"];
    
    
    
  NSLog (@ "Hassuffix =%HHD", hassuffix);
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.