详见代码:
//
// main.m
// Foundation5-NSMutableString
//
// Created by mj on 13-4-5.
// Copyright (c) 2013年 itcast. All rights reserved.
//
#import <Foundation/Foundation.h>
#pragma mark 可变字符串的创建
void stringCreate() {
// 预先分配10个字数的存储空间
NSMutableString *str = [[NSMutableString alloc] initWithCapacity:10];
// 设置字符串内容
[str setString:@"1234"];
// 拼接一个字符串
[str appendString:@"567"];
// 拼接字符串
[str appendFormat:@"age is %i and height is %.2f", 27, 1.55f];
// 替换字符串
NSRange range = [str rangeOfString:@"height"];//查找字符串height的位置
[str replaceCharactersInRange:range withString:@"no"];
// 插入字符串
[str insertString:@"abc" atIndex:2];
// 删除字符串
range = [str rangeOfString:@"age"];
[str deleteCharactersInRange:range];
NSLog(@"%@", str);
// 释放对象
[str release];
}
int main(int argc, const char * argv[])
{
@autoreleasepool {
stringCreate();
}
return 0;
}
分享到:
相关推荐
Objective-C里核心的处理字符串的类就是NSString和NSMutableString这两个类,这两个类完成了Objective-C中字符串大部分功能的处理。这两个类的最主要的区别是NSString创建赋值后不能动态修改长度和内容,除非给重新...
iOS CSV文件导出,保存 -(void)writeDict:(NSDictionary *)dict forFirst:(BOOL)first{ NSMutableString *str = [NSMutableString string]; //第一次写入字典的key值 if (first) { for (NSString *key in ...
使用方法和NSLog类似,可以将日志信息记录到文件中;可以捕捉到程序崩溃信息并记录下来。Installation将SSLogger.h SSLogger.m文件加入到工程中即可。Example// 清除七天前的日志文件SSLoggerCleanLog([[NSDate date...
Object-C 中NSString与NSMutableString 用法
功能安全访问NSArray安全访问NSDictionary安全访问并对NSMutableArray进行更改安全访问并对NSMutableDictionary进行更改安全访问并对NSMutableString进行更改要求iOS 8.0+ / macOS 10.13.6+ Xcode 10.1(10B61)+...
iOS Crash防护内容涉及 NSArray/NSMutableArray、NSDictionary/NSMutableDictionary、NSString/NSMutableString、Unrecognized Selector、KVO、KVC 、野指针定位、内存泄漏/循环引用;主要是对常见易错的地方进行...
用于ios本地动态生成验证码,效果如下: 导入CoreGraphics.framework 用于绘制图形 封装UIView,便捷使用,代码如下: AuthcodeView.h #import @interface AuthcodeView : UIView @property (strong, nonatomic...
NSMutableString * str=[[NSMutableString alloc] initWithFormat:@tel:%@,@186xxxxxxxx]; // NSLog(@str======%@,str); [[UIApplication sharedApplication] openURL:[NSURL URLWithString:str]]; 2,这种方式,打...
iOS实现拨打电话的方式: 方法一、requestWithURL,此方法拨打前弹出提示 NSMutableString * string = [[NSMutableString alloc] initWithFormat:@tel:%@,@136****0000]; UIWebView * callWebview = [[UIWebView ...
本文实例为大家分享了iOS tabview添加字母索引的具体代码,供大家参考,具体内容如下 文章转载自大神源码传送门 1、将汉字转换成首字母 //系统获取首字母 - (NSString *) pinyinFirstLetter:(NSString*)...
Software engineering,programming language,operating system,iOS,OS,iPhone,iPad objective c,cocoa touch,SDK,object oriented design,Apple,Macintosh,tools,language,runtime,Xcode,objective-...
@property (nonatomic, strong) NSMutableArray *dictionaryStack; @property (nonatomic, strong) NSMutableString *textInProgress; @property (nonatomic, strong) NSError *errorPointer;
NSMutableString *ms = [[NSMutableString alloc] initWithString:@”我是中国人”]; if (CFStringTransform((__bridge CFMutableStringRef)ms, 0, kCFStringTransformMandarinLatin, NO)) { NSLog(@”...
3、无论是声明NSString还是NSMutableString类型的属性时,我们希望此属性被赋值为NSMutableString类型的字符串后,此属性不会因这个可变类型字符串的改变而改变(这也是多数情况下的用法),那就用copy修饰属性
废话不多说,直接给大家贴关键代码了。 具体代码如下所示: #import @interface NSString (Utils) /** * 汉字的拼音 * * @return 拼音 ...NSMutableString *str = [self mutableCopy]; CFStringTransform
具体代码如下所示: // // AuthcodeView.h // BSbracelet // // Created by Christopher on 17/5/16. ...// ...@interface AuthcodeView : UIView @property (strong, ...@property (strong, nonatomic) NSMutableString
实现方法 .h文件 @property (nonatomic, retain) NSArray *changeArray; @property (nonatomic, retain) NSMutableString *changeString; @property (nonatomic, retain) UILabel *codeLabel; -(void)changeCode; ...
let mutableString = NSMutableString(string: base) CFStringTransform(mutableString, nil, kCFStringTransformToLatin, false) print(mutableString) // zhōng guó 中文转拼音(无声调) 比如:中国 -
源码WPAttributedMarkup, WPAttributedMarkup能给Label中某关键字添加文字效果或点击事件。Label中的某个关键字词可以改变字体的特性如颜色、加粗,下划线等... 详细说明:http://ios.662p.com/thread-2190-1-1.html
NSMutableString *sr=[NSMutableString stringWithFormat:@"%@",@"sdfdgdfg"]; //增加 [sr appendFormat:@"ad"]; NSLog(@"%@",sr); //增加 [sr appendFormat:@"%@",@"ad"]; NSLog(@"%@",sr); //删除 [sr ...