Nsstring form -- variable string -- Subtraction Method Delete

Source: Internet
Author: User

We have introduced the addition method and query method before. Now we will introduce the subtraction method. As the name suggests, the subtraction method definitely means to remove a part from the original string and then form a new string.

 

The method involved here:

Deletecharactersinrange:PassNsmakerangeReturned location and lengthDeletecharacterinrangeThe number of objects to be deleted from the beginning.

 

 

The following is a simple example:

#import <Foundation/Foundation.h>int main(int argc, const char * argv[]) {    @autoreleasepool {        NSMutableString *str = [NSMutableString new];        [str setString:@"0123456789"];        //删除前打印一次结果.        NSLog(@"\n%@", str);                [str deleteCharactersInRange:NSMakeRange(3, 1)];        //NSMakeRange返回一个位置和一个长度, 告诉deleteCharactersInRange        //要从哪一个字符开始删, 删除的长度是多少.                //删除后打印一次结果对比        NSLog(@"\n%@", str);    }    return 0;}

Output result:

2014-10-11 16:57:09.014 DeleteNSMutableString[1605:303] 01234567892014-10-11 16:57:09.015 DeleteNSMutableString[1605:303] 012456789Program ended with exit code: 0

 

Nsstring form -- variable string -- Subtraction Method Delete

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.