Common NSMutableString operations,

Source: Internet
Author: User

Common NSMutableString operations,

 

// Create a string // empty strings in the variable string make sense NSMutableString * mString = [[NSMutableString alloc] init]; NSLog (@ "mString: % @", mString ); // variable strings cannot be assigned with strings in the code area. NSMutableString * mString2 = @ "Hello"; // mString2 will be degraded to NSString NSLog (@ "mString2: % @", mString2); // you can specify the space size of the string to create the string NSMutableString * mString3 = [NSMutableString stringWithCapacity: 30]; NSLog (@ "mString3: % @", mString3 ); // variable string add content NSMutableString * mString4 = [NSMut AbleString alloc] initWithString: @ "Hello"]; [mString4 appendString: @ "World"]; // concatenates NSLog (@ "mString4: % @", mString4) to mString4 ); // you can add the string content [mString4 insertString: @ "123" atIndex: 5]; NSLog (@ "mString4: % @", mString4) at the specified position ); // Delete content NSMutableString * mString5 = [[NSMutableString alloc] initWithString: @ "I am learning Objective-C language. "]; // find the content of the string. the position in the string is nsange range = [mString5 rangeOfString: @" learn "]; // NSLog (@ "range: loc: % lu length: % lu", range. location, range. length); // Delete the content specified in the variable string [mString5 deleteCharactersInRange: range]; NSLog (@ "mString5: % @", mString5 ); // replace content NSMutableString * mString6 = [[NSMutableString alloc] initWithString: @ "HelloWorld! "]; [MString6 replaceCharactersInRange: NSMakeRange (4, 3) withString: @" 1234 "]; NSLog (@" mString6: % @ ", mString6 );

 

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.