Nsmutablestring Common operations

Source: Internet
Author: User

        //Creation of Strings//in a variable string, a hollow string has meaning .Nsmutablestring *mstring =[[Nsmutablestring alloc]init]; NSLog (@"mstring:%@", mstring); //mutable strings cannot be used with string assignments in code areasNsmutablestring *mstring2 =@"Hello";//MString2 will degenerate into NSString .NSLog (@"mstring2:%@", mString2); //You can specify the space size of a string to create a stringNsmutablestring *mstring3 =[nsmutablestring stringwithcapacity: -]; NSLog (@"mstring3:%@", MString3); //variable string Add contentnsmutablestring *mstring4 = [[nsmutablestring alloc]initwithstring:@"Hello"]; [MString4 appendString:@" World"];//to MString4 StitchingNSLog (@"mstring4:%@", MString4); //you can add string content at the specified location[MString4 insertstring:@"123"Atindex:5]; NSLog (@"mstring4:%@", MString4); //Delete Contentnsmutablestring *mstring5 = [[nsmutablestring alloc]initwithstring:@"I am Learning objective-c language."]; //finds the string content, where it is located in the stringNsrange range = [MString5 rangeofstring:@"Learn"];//What you need to deleteNSLog (@"Range:loc:%lu Length:%lu", range.location,range.length); //delete the specified content in a mutable string[MString5 Deletecharactersinrange:range]; NSLog (@"mstring5:%@", MSTRING5); //Replace contentnsmutablestring *mstring6 = [[nsmutablestring alloc]initwithstring:@"helloworld!"]; [MString6 Replacecharactersinrange:nsmakerange (4,3) Withstring:@"1234"]; NSLog (@"mstring6:%@", MString6);

Nsmutablestring Common operations

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.