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->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.