zoukankan      html  css  js  c++  java
  • OC5_NSMutableString操作

    //
    //  main.m
    //  OC5_NSMutableString操作
    //
    //  Created by zhangxueming on 15/6/10.
    //  Copyright (c) 2015年 zhangxueming. All rights reserved.
    //
    
    #import <Foundation/Foundation.h>
    //NSMutableString 继承与NSString
    //所有NSString类的方法NSMutableString 都可以使用
    
    int main(int argc, const char * argv[]) {
        @autoreleasepool {
            //创建指定容量大小的可变字符串对象
            //+ (NSMutableString *)stringWithCapacity:(NSUInteger)capacity;
            NSMutableString *mulStr1 = [[NSMutableString alloc] initWithCapacity:20];
            NSLog(@"mulStr1 = %@", mulStr1);
            
            //替换指定范围内的字符
            //- (void)replaceCharactersInRange:(NSRange)range withString:(NSString *)aString;
            NSMutableString *mulStr2 = [[NSMutableString alloc] initWithString:@"hello world qianfeng"];
            [mulStr2 replaceCharactersInRange:NSMakeRange(6, 5) withString:@"welcome"];
            NSLog(@"mulStr2 = %@", mulStr2);
            
            //在指定位置增加字符串
            NSMutableString *mulStr3 = [[NSMutableString alloc] initWithFormat:@"千锋中国"];
            [mulStr3 insertString:@"hello world" atIndex:2];
            NSLog(@"mulStr3 = %@", mulStr3);
            
            //删除指定范围内的字符
            NSMutableString *mulStr4 = [NSMutableString stringWithUTF8String:"千锋hello world中国"];
            [mulStr4 deleteCharactersInRange:NSMakeRange(2, 11)];
            NSLog(@"mulStr4 = %@", mulStr4);
            
            //追加字符串
            NSMutableString *mulStr5 = [NSMutableString stringWithString:@"helloworld"];
            [mulStr5 appendString:@"qianfeng"];
            NSLog(@"mulStr5 = %@", mulStr5);
            
            //格式化追加字符串
            NSMutableString *mulStr6 = [NSMutableString stringWithFormat:@"%s%d", "hello", 12345];
            [mulStr6 appendFormat:@"%.2f%@", 3.14, @"world"];
            NSLog(@"mulStr6 = %@", mulStr6);
            
            //修改字符串
            NSMutableString *mulStr7 = [[NSMutableString alloc] initWithString:@"hello world"];
            [mulStr7 setString:@"qianfeng"];
            NSLog(@"mulStr7 = %@", mulStr7);
            
        }
        return 0;
    }
  • 相关阅读:
    将make的输出重定向到文件
    ubuntu mount u盘以及cp拷贝文件夹
    Emacs Tutorial摘录
    c#实现每隔一段时间执行代码(多线程)
    socket.BeginReceiveFrom异步接收信息时,回调函数无法正常进入
    23个C#实用技巧
    C#中实现Form的透明属性变化即渐隐效果
    C#键位定制:设置一个文本框只能输入数字键
    byte 与 bit 的转换
    C# Socket UDP 案例 2
  • 原文地址:https://www.cnblogs.com/0515offer/p/4566859.html
Copyright © 2011-2022 走看看