Variable string insertion Delete re-assignment replace prefix length

Source: Internet
Author: User

#import <Foundation/Foundation.h>

int main (int argc, const char * argv[]) {

@autoreleasepool {

NSString Parent class nsmutablestring variable string subclass

Nsmutablestring *mustr=[[nsmutablestring Alloc]init];

Nsmutablestring *mustr1=[nsmutablestring stringwithformat:@ "Hello"];

Place immutable strings inside a mutable string

NSString *[email protected] "Welcome to OC";

Mustr=[nsmutablestring STRINGWITHSTRING:STR];

Insert

[Mustr insertstring:@ "Students" atindex:7];

[Mustr appendstring:@ "Teacher"];

[Mustr appendformat:@ "second pass insert:%@", str];

Delete

[Mustr Deletecharactersinrange:nsmakerange (8, 10)];

Find and delete

Nsrange rang=[mustr rangeofstring:@ "second pass insert: Welcome to OC"];

if (rang.location!=nsnotfound) {

[Mustr Deletecharactersinrange:rang];

}

Re-assign Value

[Mustr SETSTRING:STR];

Replace

Nsrange rang1=[mustr rangeofstring:@ "OC"];

[Mustr replacecharactersinrange:rang1 withstring:@ "IOS"];

NSLog (@ "%@", mustr);

Determines whether a string has a prefix

NSString *[email protected] "ios8-Zhao Yuxin. jpg";

BOOL result = [str hasprefix:@ "IOS"];

NSLog (@ "%d", result);

Determines whether a string has a suffix

BOOL Resultsu = [str hassuffix:@ ". jpg"];

NSLog (@ "%d", Resultsu);

Length

1. Defining a String Object

NSString *str=[nsstring stringwithstring:@ "Zi fu Chuan"];

2. Calculating string Lengths

Nsuinteger len = [str length];

3. Output string length

NSLog (@ "Zi fu chuan length is%ld", Len);

}

return 0;

}

Variable string insertion Delete re-assignment replace prefix length

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.