NSMutableString -- variable string, nsmutablestring --

Source: Internet
Author: User

NSMutableString -- variable string, nsmutablestring --

//// Main. m // OC04-task-05 // Created by keyzhang on 15-1-24. // Copyright (c) 2015 keyzhang. all rights reserved. // # import <Foundation/Foundation. h> int main (int argc, const char * argv []) {@ autoreleasepool {// insert code here... //// // NSMutableString -- variable string // NSMutableString inherited from NSString // initWithFormat: is the method of the parent class used NSMutableString * str1 = [[NSMutableString alloc] initWithFormat: @ "abc"]; NSLog (@ "str1 is % @", str1 ); // create an empty string NSMutableString * str2 = [NSMutableString string]; NSLog (@ "str2 is % @", str2); // insert a string, on the original basis, modify [str1 insertString: @ "hello world" atIndex: 0]; NSLog (@ "str1 is % @", str1 ); // Delete the string nsange range = {11, 3}; [str1 deleteCharactersInRange: range]; NSLog (@ "str1 is % @", str1); // append the string, append the string directly to [str1 appendString: @ "hehe"]; NSLog (@ "str1 is % @", str1); int index = 123456; [str1 appendFormat: @ "% d", index]; NSLog (@ "str1 is % @", str1); // specify a range and replace [str1 replaceCharactersInRange: NSMakeRange (0, 5) withString: @ "a"]; NSLog (@ "str1 is % @", str1); // note: you need to compare and learn the corresponding method of immutable string // The variable string append string method is modified based on your own, this method does not return a value // [str1 appendFormat: <# (NSString *),... #>]; // the immutable string append string method has a return value. The append string is returned. // [str1 stringByAppendingFormat: <# (NSString *),... #>]} return 0 ;}

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.