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