NSString

字符串创建:

  1.NSString *strr = @"0123456789";

2.NSString *str = [NSString stringWithString:strr];

    3.NSString *fstr = [NSString stringWithFormat:@"age = %d",age];

字符串长度;

NSUInteger len = str.length;

字符串获取子字符串:

1.NSString *fromStr = [str substringFromIndex:4];

2.NSString *toStr = [str substringToIndex:4];

3.NSRange range =NSMakeRange(4, 2);

NSString *rangeStr = [str substringWithRange:range];

字符串比较:

    1.if([@"abc" isEqualToString:@"abc"])  //返回YES NO

2.NSComparisonResult result =[@"abc" compare:@"bc"];

switch (result) {

case NSOrderedSame:

NSLog(@"same");

break;

case NSOrderedAscending:

NSLog(@"abc<bc");

break;

case NSOrderedDescending:

NSLog(@"abc>bc");

break;

default:

break;

}

字符串查找:

      NSString *url = @"http://www.baidu.com";

1.if ([url hasPrefix:@"http"])  //前缀

2.if ([url hasSuffix:@"com"]) //后缀

3.//字符串位置

NSRange rr =[url rangeOfString:@"www"];

if (rr.length) {

NSLog(@"%ld  %ld",rr.location,rr.length);

}else{

NSLog(@"not found");

}

字符串转换:

    //字符串转为数字  只把开头的数字转过来

NSString * heightStr = @"166.5";

float height = [heightStr floatValue];

//数字转为字符串

NSString *formatStr = [NSString stringWithFormat:@"height = %f",height];

NSMutableString

预留内存空间:

NSMutableString *mstr = [[NSMutableString alloc]initWithCapacity:0];

NSMutableString *mstr = [NSMutableString stringWithCapacity:0];

追加:

[mstr appendString:@"小王子"];

int num = 1;

[mstr appendFormat:@"%d 小王子", num ];

插入:

[mstr insertString:@"《" atIndex:0];

[mstr insertString:@"》" atIndex:mstr.length];

改:

NSRange rm =[mstr rangeOfString:@"小王子"];

[mstr replaceCharactersInRange:rm withString:@"大王子"];

重置:

[mstr setString:@"大王子"];

删:

NSRange rmm =[mstr rangeOfString:@"大"];

[mstr deleteCharactersInRange:rmm];

Foundation--NSString+NSMutableString的更多相关文章

  1. NSString&NSMutableString常用操作梳理(转)

    作者:弦苦 授权本站转载. 上一篇梳理了NSArray&NSMutableArray常用操作,这次来梳理一下Objective-C中每天都要用到的字符串处理类——NSString. Objec ...

  2. NSString&NSMutableString常用操作梳理

    http://www.cocoachina.com/ios/20150724/12722.html 上一篇梳理了NSArray&NSMutableArray常用操作,这次来梳理一下Object ...

  3. Objective-C NSString/NSMutableString

    创建于完成: 2018/02/05 总览: http://www.cnblogs.com/lancgg/p/8404975.html  字符串类  简介  字符码: Unicode  NSString ...

  4. 关于NSString,NSMutableString,NSArray,NSMutableArray,NSDictionary,NSMutableDictionary

    NSString,NSMutableString,NSArray,NSMutableArray,NSDictionary,NSMutableDictionary 在 OC 中我们天天都要用,而我们要怎 ...

  5. NSString NSMutableString copy mutableCopy retain weak strong整合

    copy retain assign的差别在于对象属性的set方法 NSString 与 NSMutableString NSString是不可变字符串对象,这句话的意思,结合代码: #import ...

  6. [转] NSString / NSMutableString 字符串处理,常用代码

     原文 :  http://justcoding.iteye.com/blog/1405951 Objective-C 中核心处理字符串的类是 NSString 与 NSMutableString , ...

  7. 【转】 NSString / NSMutableString 字符串处理,常用代码 (实例)

    Objective-C 中核心处理字符串的类是 NSString 与 NSMutableString ,这两个类最大的区别就是NSString 创建赋值以后该字符串的内容与长度不能在动态的更改,除非重 ...

  8. NSString / NSMutableString 字符串处理,常用代码 (实例)

    http://blog.csdn.net/likendsl/article/details/7417878 Objective-C 中核心处理字符串的类是 NSString 与 NSMutableSt ...

  9. NSString NSMutableString

    // NSString         //代开API文档         //Xcode -> help - Documentation and API Reference           ...

  10. (转载)OC学习篇之---Foundation框架中的NSString对象和NSMutableString对象

    在之前的一篇文章中我们说到了Foundation框架中的NSObject对象,那么今天在在来继续看一下Foundation框架中的常用对象:NSString和NSMutableString. 在OC中 ...

随机推荐

  1. DBHelper 类(网上收集)

    这个是我网上找的,觉得不错的一个DBHelper类,下面是作者话: // 微软的企业库中有一个非常不错的数据操作类了.但是,不少公司(起码我遇到的几个...),对一些"封装"了些什 ...

  2. iOS指纹识别

    #import "ViewController.h" #import <LocalAuthentication/LocalAuthentication.h> @inte ...

  3. String.format Tutorial

    String format(String format, Object... args) The format specifiers for general, character, and numer ...

  4. (原+转)ubuntu中删除文件夹

    转载请注明出处: http://www.cnblogs.com/darkknightzh/p/5638030.html 参考网址: http://zhidao.baidu.com/link?url=A ...

  5. 一大坨GoogleAPI的学习笔记之一(oAuth2.0)

    官方文档地址:https://developers.google.com/accounts/docs/OAuth2InstalledApp 最近Ubuntu下VGA接口无端的不能用了,木有心情翻译了, ...

  6. css派生选择器

    后代选择器:即包含选择器,选择某元素的后代元素. 子元素选择器:只能选择某元素的子元素. 相邻兄弟选择器:可选择紧接在另一个元素后的元素,且两者有相同的夫元素.

  7. LinearLayout的一些注意事项

    1.orientation的默认值为horizontal,即从左向右排列.由于一般从上向下排列,所以必须指定orientation属性. 2.layout_gravity与gravity的区别: (1 ...

  8. POJ Find The Multiple 1426 (搜索)

    Find The Multiple Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 22576   Accepted: 929 ...

  9. javascript跨域获取json数据

    项目在开发过程中,用到了天气预报的功能,所以需要调用天气预报的api,一开始以为直接用ajax调用url就可以获取天气数据,结果涉及到了跨域的问题,这里做一个记录. 说到跨域,就得知道同源策略. 同源 ...

  10. HttpClient3.1设置header信息

    HttpClient client = new HttpClient(); GetMethod get = new GetMethod(URL); get.setRequestHeader(" ...