OC 字符串出来
//1.获取字符串的长度
NSString * str = @"abcd";
NSUInteger length = [str length]; //str.length;
NSLog(@"字符串长度 %lu",length);
//2.根据索引获得单个字符
NSString * str2 = @"www.itcast.cn";
//如果你给定的索引值,超出了字符串的长度,就会导致异常Range or index out of bounds
//如果你给入的是一个负数那么获得的值就是一个乱码
unichar c = [str2 characterAtIndex:2];//索引值是从 0 开始的
NSLog(@"获得字符 %c",c);
//3.根据索引获得字符串的一个子串
NSString * str3 = @"www.itcast.com";
//substringFromIndex 从给定的索引开始(包含该索引位置)截取到字符串末尾
NSString * tmpStr = [str3 substringFromIndex:3];
NSLog(@"substringFromIndex %@ ",tmpStr);
//substringToIndex截取字符串到给定索引的位置结束,(不包含该索引位置);qishisuo
NSString * tmpStr2 = [str3 substringToIndex:3];
NSLog(@"substringToIndex %@",tmpStr2);
NSLog(@"str3 %@",str3);
//4.截取字符串的某一段/Volumes/aplle/Desktop/共享课堂/0320/代码/01-NSString类/01-NSString类.xcodeproj
NSRange rang = {4,6};
//location (起始索引的位置,包含该索引) length(要截取的长度)
NSString * tmpStr3 = [str3 substringWithRange:rang];
NSLog(@"substringWithRange %@",tmpStr3);
//5.获得一个字符串的索引位置
NSString * tmpStr4 = @"it";//@"itcast";
NSRange tmpRange = [str3 rangeOfString:tmpStr4];
//可以使用NSStringFromRange 把一个Range结构体转换成字符串
// NSLog(@"location = %d,length = %d",tmpRange.location,tmpRange.length);
//NSNotFound 没有找到
if (tmpRange.location == NSNotFound)
{
NSLog(@"tmpStr4 不在 Str3中");
}else
{
NSLog(@"rangeOfString %@",NSStringFromRange(tmpRange));
}
//6.获的一个字符串索引范围
NSRange tmpRange2 = [str3 rangeOfString:@"itcast" options:NSCaseInsensitiveSearch];
NSLog(@"rangeOfString1 %@",NSStringFromRange(tmpRange2));
OC 字符串出来的更多相关文章
- OC字符串常用函数
创建一个字符串对象: NSstring * str1 = @"hello"; NSString * str = [[NSString alloc]initWithString:@& ...
- OC字符串的常用方法
网上写的关于字符串常用方法的博客很多,这里我简单做了下总结!不喜勿喷哦! 一.创建字符串 #import <Foundation/Foundation.h> //NSString //创建 ...
- c语言字符串转OC字符串
// 如果把c语言字符串转OC字符串,@(C字符串) char *c = "abc"; NSLog(@"%@", @(c));
- OC字符串与C语言字符串之间的相互转换
1.C转OC字符串 const char *cString = "This is a C string"; // 动态方法 NSString *ocString1 = [[NSSt ...
- OC字符串NSString
========================== 面向对象编程进阶和字符串 ========================== Δ一.类的设计模式—单例 [单例]程序允许过程中,有且仅有一块内存 ...
- oc 字符串
#import <Foundation/Foundation.h> int main(int argc, const char * argv[]) { @autoreleasepool { ...
- OC字符串的一些常用的函数。
)//获取字符串长度 NSUInteger len= str.length; () //通过指定索引返回对应的字符 unichar ch =[str characterAtIndex:]; ()//通 ...
- C 和 OC 字符串转换 NSString 和 char * 转换 const char* 与 char *
#import <Foundation/Foundation.h> int main(int argc, const char * argv[]) { char *s = "He ...
- QF——OC字符串
OC中的字符串: C中没有字符串类型,用字符数组和指针代替. OC中引入了字符串类型,它包括NSString 和 NSMutableString两种 NSString是不可变的,已经初始化便不能更改: ...
- OC字符串的使用(一)
#import <Foundation/Foundation.h> int main(int argc, const char * argv[]) { @autoreleasepool { ...
随机推荐
- 使用GIT进行源码管理 —— VisualStudio官方GIT教程
我之前在文章使用GIT进行源码管理 —— 在VisualStudio中使用GIT中简单的介绍了一下如何使用VS中自带的Git工具,今天发现MSDN上现在也有了非常完整的教程,感兴趣的朋友可以看一下: ...
- DataRow 数组转化成DataTable
#region 封装DataTable DataTable dt = null; if (newRows.Length > 0) { dt = newRows[0].Table.Clone(); ...
- ubi层次
转:http://www.360doc.com/content/11/0518/13/496343_117643185.shtml UBI是什么? 它是一种flash管理方式 flash是一系列连续的 ...
- C语言 printf格式化输出,参数详解
有关输出对齐 int main(int argc, char* argv[]){ char insertTime[20] = {"1234567890"}; double in ...
- IIS 日志
查看工具: Log Parser + Log Parser Studio http://www.microsoft.com/en-us/download/details.aspx?displaylan ...
- 转:http2的资料与使用
https://imququ.com/post/http2-resource.html
- Foundation框架 - NSNumber类
NSNumber类 NSFormatter #import <Foundation/Foundation.h> int main(int argc, const char * argv[] ...
- Jquery获取当前行的数据
取表格当前行数据js代码: Java代码 $(function() { $(".myclass").each(function(){ var tmp=$(this).chi ...
- [Angular] Control the dependency lookup with @Host, @Self, @SkipSelf and @Optional
Very differently to AngularJS (v1.x), Angular now has a hierarchical dependency injector. That allow ...
- python对象序列化或持久化的方法
http://blog.csdn.net/chen_lovelotus/article/details/7233293 一.Python对象持久化方法 目前为止,据我所知,在python中对象持久化有 ...