zoukankan      html  css  js  c++  java
  • 可变字符串

    //

    //  main.m

    //  可变的字符串

    //

    //  Created by 博博 on 16/1/7.

    //  Copyright (c) 2016年 com.bb. All rights reserved.

    //

    #define NSLog(FORMAT, ...) printf("%s ", [[NSString stringWithFormat:FORMAT, ##__VA_ARGS__] UTF8String])

    #import <Foundation/Foundation.h>

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

        @autoreleasepool {

            //nsstring父类  可变字符串子类

            NSMutableString *mustr=[[NSMutableString alloc]init];

            NSMutableString *mustr1=[NSMutableString stringWithFormat:@"hello"];

            NSLog(@"str=%@",mustr1);

            NSString *str=@"welcome to oc";

            mustr=[NSMutableString stringWithString:str];

            NSLog(@"%@",mustr);

            

            //插入

            [mustr insertString:@" student" atIndex:7];

            NSLog(@"%@",mustr);

            [mustr appendString:@" teacher"];//插入末尾

            NSLog(@"%@",mustr);

            [mustr appendFormat:@"第二遍:%@",str];

            NSLog(@"%@",mustr);

            //删除

            [mustr deleteCharactersInRange:NSMakeRange(8, 9)];

            NSLog(@"%@",mustr);

            //查找并删除

            NSRange rang=[mustr rangeOfString:@"teacher第二遍:welcome to oc"];

            if(rang.location!=NSNotFound){

                [mustr deleteCharactersInRange:rang];

            }

            NSLog(@"%@",mustr);

            //重新赋值

            [mustr setString:str];

            NSLog(@"%@",mustr);

            //替换

            NSRange rang1=[mustr rangeOfString:@"oc"];

            [mustr replaceCharactersInRange:rang1 withString:@"ios"];

            NSLog(@"%@",mustr);

        }

        return 0;

    }

  • 相关阅读:
    PHP + JQuery 实现多图上传并预览
    推荐40个专业的CMS下载
    10 个有用的 PHP 代码
    2012年最值得关注最具颠覆性的10个创业公司
    在线生成 CSS3 的工具
    循环显示/隐藏图片
    100个推荐的图片/内容滑动条
    jQuery 下拉菜单插件
    20个网站测试工具
    20个免费在线生成网站
  • 原文地址:https://www.cnblogs.com/bobohahaha/p/5120913.html
Copyright © 2011-2022 走看看