zoukankan      html  css  js  c++  java
  • 可变字符串 插入 删除 重赋值 替换 前后缀 长度

    #import <Foundation/Foundation.h>

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

        @autoreleasepool {      

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

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

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

      //将不可变的字符串放置到可变字符串内

          NSString *str=@"welcome to oc"; 

            mustr=[NSMutableString stringWithString:str];

      //插入

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

            [mustr appendString:@" teacher"];

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

      //删除

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

      //查找并删除        

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

            if (rang.location!=NSNotFound) {

                [mustr deleteCharactersInRange:rang];

            }

         //重新赋值

            [mustr setString:str];

          //替换

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

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

            NSLog(@"%@",mustr);

      //判断字符串是否有此前缀

            NSString *str=@"IOS8-赵玉鑫.jpg";

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

            NSLog(@"%d",result);

           //判断字符串是否有此后缀

          BOOL resultsu = [str hasSuffix:@".jpg"];

            NSLog(@"%d",resultsu);

     长度

    //1.定义字符串对象

            NSString *str=[NSString stringWithString:@"zi fu chuan"];

            //2.计算字符串长度

            NSUInteger len = [str length];

            //3.输出字符串长度

            NSLog(@"zi fu chuan的长度是%ld",len);

        }

        return 0;

    }

  • 相关阅读:
    遭遇:“传入的表格格式数据流(TDS)远程过程调用(RPC)协议流不正确” 错误
    JS控制form表单action去向
    easyui form 提交问题,纠结了很久,有点诡异
    easyui的tab加载页面中的form重复提交
    AJAX POST请求中参数以form data和request payload形式在servlet中的获取方式
    $.AJAX参数提交及后台获取方式
    多条件判断语句case
    条件判断语句if
    条件测试和捕获信号
    向脚本传递参数
  • 原文地址:https://www.cnblogs.com/j-h-t-123-n/p/5116208.html
Copyright © 2011-2022 走看看