All operations for iOS variable strings

Source: Internet
Author: User

Can directly copy the code can be combined with output to see the results deepen memory

Create a mutable string

nsmutablestring * ms1 = [[nsmutablestring alloc]init];

//Can be created by using the class method

nsmutablestring * MS2 = [nsmutablestring string];

Create a mutable string using the Format method

MS1 = [nsmutablestring stringwithformat:@ "%d", 12];

//Specify initialization size Create a mutable string (create a string of length 10)

MS1 = [[nsmutablestring alloc]initwithcapacity:10];

//Create a variable string with another specified string

MS2 = [nsmutablestring stringwithstring:ms1];

#pragma mark Stitching string

Stitching strings

[Ms1 appendstring:@ "345"];

[Ms1 appendstring:@ "welcome You"];

//Format stitching

[Ms1 appendformat:@ "%@", @ "come to Huludao"];

NSLog (@ "%@", MS1);

#pragma mark Insert String

//Inserts a string at the specified location

[Ms1 insertstring:@ "brother" atindex:3];//location

#pragma mark Replacement

Substitutes the supplied string for the contents of the specified range for the original character

[Ms1 replacecharactersinrange:nsmakerange (0, 3) withstring:@ "B elder brother"];

NSLog (@ "%@", MS1);

#pragma mark to delete a string

[Ms1 Deletecharactersinrange:nsmakerange (3,5)];

NSLog (@ "%@", MS1);

#pragma mark Setup Content

Re-set string contents

[Ms1 setstring:@ "root all ills"];

NSLog (@ "%@", MS1);

All operations for iOS variable strings

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.