NSString几个函数
第一、判断是否包含前缀于后缀
NSString *str=@"hello andy yang";
if([str hasPrefix:@"hello"])
{
NSLog(@"the prefix is hello");
}
if([str hasSuffix:@"yang"])
{
NSLog(@"the suffix is yang");
}
第二、NSRange
typedefstruct _NSRange {
NSUInteger location; //开始位置
NSUInteger length; //长度
} NSRange;
NSRange的定义:
NSRange range2;
range2.location = 17;
range2.length = 4;
NSLog(@"%lu and %lu",range2.location,range2.length);
//用NSMakeRange来初始化
NSRange rang1=NSMakeRange(12, 23);
NSLog(@" %lu and %lu",rang1.location,rang1.length);
第三、 rangeOfString函数的使用
NSRange range;
range=[str rangeOfString:@"andy"];
NSLog(@"%lu and %lu",range.location,range.length);
第四、compare实现函数的比较
NSString *str1=@"AA";
NSString *str2=@"aBB";
if ([str2 compare:str1])
{
NSLog(@"%@ is larger than %@",str1,str2);
}else
{
NSLog(@"%@ is larger than %@",str2,str1);
}
第五、NSMutabelString 继承自NSString
- (void)appendString:(NSString *)aString;
- (void)appendFormat:(NSString *)format, ... NS_FORMAT_FUNCTION(1,2);
sample code:
NSMutableString
*str=[
NSMutableString
stringWithCapacity
:
12
];
[str appendString:@"hello"];
NSLog(@"str is %@",str);
[str appendFormat:@" andy yang %d",11];
NSLog(@"str is %@",str);
- (void)deleteCharactersInRange:(NSRange)range; 删除字符串
NSMutableString *str1=[NSMutableString stringWithFormat:
@"hello what is your name?"];
NSRange range;
range=[str1 rangeOfString:@"what"];
NSLog(@"start is %lu,length is %lu",range.location,range.length);
[str1 deleteCharactersInRange:range];
NSLog(@"str is %@",str1);
NSString几个函数的更多相关文章
- swift 学习(二)基础知识 (函数,闭包,ARC,柯里化,反射)
函数 func x(a:Int, b:Int) {} func x(a:Int, b:Int) -> Void {} func x(a:Int, b:Int) ->(Int,Int ...
- OC可变參数的函数实现va_start、va_end、va_list的使用
一.简单介绍 我们常常在编程的时候看见类似这种代码,如图1.1 图1.1 或者是这种可变參数,如图1.2 图1.2 二.基本知识介绍 在学习怎样写这样的格式的函数前,先简介几个经常使用的宏: 下面摘自 ...
- 【原】AFNetworking源码阅读(六)
[原]AFNetworking源码阅读(六) 本文转载请注明出处 —— polobymulberry-博客园 1. 前言 这一篇的想讲的,一个就是分析一下AFSecurityPolicy文件,看看AF ...
- 【原】AFNetworking源码阅读(二)
[原]AFNetworking源码阅读(二) 本文转载请注明出处 —— polobymulberry-博客园 1. 前言 上一篇中我们在iOS Example代码中提到了AFHTTPSessionMa ...
- 1.2.1 OC概述
本文并非最终版本,如想关注更新或更正的内容,详见文末的联系方式,如有疏忽和遗漏,欢迎指正. 本文相关目录:(链接为简书链接) ====================== 所属文集:1.2 Objec ...
- AFNetworking到底做了什么
写在开头: 作为一个iOS开发,也许你不知道NSUrlRequest.不知道NSUrlConnection.也不知道NSURLSession...(说不下去了...怎么会什么都不知道...)但是你一定 ...
- UITextView: 响应键盘的 return 事件(收回键盘)
UITextView: 响应键盘的 return 事件(收回键盘) 此篇文章将要介绍UITextView: 响应键盘的 return 事件(收回键盘)的相关介绍,具体实例请看下文 UITextView ...
- 论文第4章:iOS绘图平台的实现
面向移动设备的矢量绘图平台设计与实现 Design and Implementation of Mobile Device-oriented Vector Drawing Platform 引用本论文 ...
- Objective-C 2.0的运行时编程
Objective-C 2.0 的运行时环境叫做Morden Runtime,iOS 和Mac OS X 64-bit 的程序都运行在这个环境,也就是说Mac OS X 32-bit 的程序运行在旧的 ...
随机推荐
- 使用Freemarker宏进行可扩展式模块化编程
作者:Chu Lung 原文链接:http://blog.chulung.com/article/13 本文由MetaCLBlog于2016-07-08 14:42:10自动同步至cnblogs 一. ...
- [前端_EasyUI]给easyui的datebox设置默认值,获取不到 的解决方法
//给eayui datebox设置初始值 $("#ctime").datebox("setValue", function(){ var date = new ...
- 第九十七天请假 PHP TP框架 MVC模式
MVC : M->Model 模型(数据层) V->View 视图(视图层) C->Controller 控制器(逻辑层) M : 操作数据(连接数据 ...
- 3.openssl speed和openssl rand
(1).openssl speed 测试加密算法的性能. 支持的算法有: openssl speed [md2] [mdc2] [md5] [hmac] [sha1] [rmd160] [idea-c ...
- 怎么提高ArcSDE 写入地理数据库的效率
link: http://blog.csdn.net/linghe301/article/details/20900615 2014-03-14 09:20 2686人阅读 评论(6) 收藏 举报 ...
- 使用CocoaPods配置工程
1.首先搭建环境,配置CocoaPods,具体请参考 http://code4app.com/article/cocoapods-install-usage 2.打开终端,输入 cd 空格 把工程拖入 ...
- JSTL和EL的区别
JSTL(JSP Standard Tag Library,JSP标准标签库)是一个不断完善的开放源代码的JSP标签库,是由apache的jakarta小组来维护的.JSTL只能运行在支持JSP1.2 ...
- swift 代码添加lable
let lable1 = UILabel(frame: CGRect(x: CGFloat(self.view.bounds.width/2-20), y: CGFloat(history.frame ...
- smarty模板原理
smarty模板原理 模板主要是用来让前端和后端分离的,前台页面只是一个前台页面,后台页面用php代码写逻辑,写完逻辑拿到前台显示. 一.写法 一般需要以下:写3个页面: 1.显示页面aa.htm ...
- ios NSThred多线程简单使用
关于NSThred开启多线程的方法 - (void)performSelectorInBackground:(SEL)aSelector withObject:(id)arg [self perfor ...