IOS Study Notes 2015-03-24 OC-API-Immutable string, 2015-03-24oc-api-
Mostly imitation
//// Main. m // OC-API-Immutable string /// Created by wangtouwang on 15/3/25. // Copyright (c) 2015 wangtouwang. all rights reserved. // # import <Foundation/Foundation. h> // initialize void testInit () {// create a C String object char str0 = "C String "; // to create a String object, you do not need to release the memory NSString * str1 = @ "MAIKE"; // to create a String object, you need to release the memory NSString * str2 = [[NSString alloc] initWithString: @ "JACK"]; NSString * str3 = [[NSString alloc] initWithFormat: @ "LUCY % I", 12]; NSString * str4 = [[NSString alloc] initwithuf8string: "C String"]; // all the above methods have STATIC methods, and do not need to release the memory str2 = [NSString stringWithString: @ "static jack"]; str3 = [NSString stringWithFormat: @ "static lucy % I", 12]; str4 = [NSString stringwithuf8string: "C String"];} int main (int argc, const char * argv []) {@ autoreleasepool {// convert to NSLog (@ "zhangjianhua to uppercase % @", [@ "zhangjianhua" uppercaseString]); // convert to lowercase NSLog (@ "ZHANGJIANHUA to lowercase % @", [@ "ZHANGJIANHUA" lowercaseString]); // upper-case NSLog (@ "zhangjianhua to lower-case % @", [@ "zhangjianhua" capitalizedString]); // compare the string content NSLog (@ "ABC isEqualToString Abc to result = % I", [@ "ABC" isEqualToString: @ "Abc"]); // compare the string content with NSComparisonResult result2 = [@ "abc" compare: @ "aBc"]; // if it is [@ "abc" caseInsensitiveCompare: @ "aBc"], if (result2 = NSOrderedAscending) {NSLog (@ "left <right. ");} else if (result2 = NSOrderedDescending) {NSLog (@" left> right. ");} else if (result2 = NSOrderedSame) {NSLog (@" left = right. ");} // query the position of the specified string in the prefix NSLog (@" abcdefj by cd in location % I ", [@" ABCDEFJ "hasPrefix: @" CD "]); // query the position of the specified string in the suffix NSLog (@ "abcdefj by fj in location % I", [@ "ABCDEFJ" hasSuffix: @ "F"]); // query the position and length of a specified string NSLog (@ "abcdefj by cd in location % @", NSStringFromRange ([@ "ABCDEFJ" rangeOfString: @ "CD"]); // truncate the specified string position based on the NSLog (@ "JAVA Subetring TO Result % @", [@ "ABCDEFG" substringWithRange: NSMakeRange (2, 2)]) of the CGRange object; // intercept the NSLog (@ "SubString String By Index % @", [@ "ABCDEFG" substringToIndex: 2]) when the specified String object reaches this position based on the subscript. // intercept the NSLog (@ "SubString String By Index % @", [@ "ABCDEFG" substringFromIndex: 2]) of the specified String object from position to end based on the subscript. // string segmentation NSString * str9 = @ "my name is wp, AGE = 28"; NSArray * array = [str9 componentsSeparatedByString: @ ""]; NSLog (@ "% @", array); // convert the data type to int NSLog (@ "% I", [@ "13" intValue]); // convert to C voice string const char * s = [@ "abc" UTF8String]; // convert to C-language string NSLog (@ "% s", s ); NSLog (@ "% c", [@ "abc" characterAtIndex: 0]); // retrieves the character from the specified position} return 0 ;}