Common NSString operations,
NSString * testStr01 = @ "HelloWord"; NSString * testStr02 = [testStr01 substringToIndex: 5]; // obtain the header (from the beginning ), to does not include the subscript content NSString * testStr03 = [testStr01 substringFromIndex: 5]; // tail (from where to the end), from contains the subscript content NSLog (@ "testStr02: % @ testStr03: % @ ", testStr02, testStr03); nsange r = {4, 3}; // obtain the length of NSString * testStr04 = [testStr01 substringWithRange: r]; NSLog (@ "testStr04: % @", testStr04); // String concatenation NSString * testStr05 = @ "Hello"; // append NSString * testStr06 = [testStr05 stringByAppendingString: @ "World"]; NSLog (@ "testStr06: % @", testStr06); // initialize NSString * testStr07 = @ "Hello"; NSString * testStr08 = @ "World "; NSString * testStr09 = [NSString stringWithFormat: @ "% @", testStr07, testStr08]; NSString * testStr10 = [NSString stringWithFormat: @ "Hello % @", testStr08]; NSLog (@ "testStr09: % @", testStr09); NSLog (@ "testStr10: % @", testStr10); // in the specified format (range) append content NSString * testStr11 = @ "Hello"; NSString * testStr12 = [testStr11 stringByAppendingFormat: @ "% @", @ "World", @ "123"]; NSLog (@ "testStr12: % @", testStr12); // replace NSString * testStr13 = @ "www.kyle.com.cn"; NSString * testStr14 = [testStr13 kernel: NSMakeRange (4, 6) withString: @ "163"]; NSLog (@ "testStr14: % @", testStr14 ); // set of parameters // the path of the parameter file does not include the file name NSString * path = @ "/Users/apple/Desktop"; // path = [path stringByAppendingString: @ "/test.txt"]; path = [path stringByAppendingString: @ "/test. rtf "]; // read the content of the file to a string // NSString * str20 = [[NSString alloc] initWithContentsOfFile: path]; NSString * testStr15 = [[NSString alloc] initWithContentsOfFile: path encoding: NSUTF8StringEncoding error: nil]; NSLog (@ "testStr15: % @", testStr15 ); NSString * use = @ "fcp"; NSString * use1 = @ "fcp"; NSString * password = @ "123"; NSString * password1 = @ "123 "; if ([use isEqualToString: use1] & [password isEqualToString: password1]) {NSLog (@ "Login successful");} else {NSLog (@ "Login Failed ");}