Swift - 16 - String.Index和Range
//: Playground - noun: a place where people can play import UIKit var str = "Welcome to Play Swift! Step by Step learn Swift language from now!" // range
str.rangeOfString("Step") // 默认从前面开始搜索
str.rangeOfString("Step", options: NSStringCompareOptions.BackwardsSearch, range: nil, locale: nil) // 从后面开始搜索 str.startIndex
str.endIndex
var strRange = Range<String.Index>(start: str.startIndex, end: str.endIndex) // 搜索特定范围中特定字符串的范围
var searchStartIndex:String.Index = str.startIndex // 搜索开始的位置
var searchEndIndex:String.Index = searchStartIndex.advancedBy(7) // 搜索结束的位置
let searchRange = Range<String.Index>(start: searchStartIndex, end: searchEndIndex)
str.rangeOfString("Step", options: NSStringCompareOptions.CaseInsensitiveSearch, range: searchRange, locale: nil) // subString
var toIndex = str.startIndex.advancedBy(4)
str.substringToIndex(toIndex) var fromIndex = str.startIndex.advancedBy(14)
str.substringFromIndex(fromIndex) str.substringWithRange(searchRange) // insert
var insertIndex = searchStartIndex.advancedBy(22)
str.insert("!", atIndex: insertIndex); // remove
str.removeAtIndex(insertIndex)
str.removeRange(searchRange) // replace
var replaceRange = Range<String.Index>(start: str.startIndex, end: str.startIndex.advancedBy(14))
str.stringByReplacingCharactersInRange(replaceRange, withString: "Rinpe Chan") // String.Index 也是一种数据类型
Swift - 16 - String.Index和Range的更多相关文章
- Swift 中 String 取下标及性能问题
		
Swift 中 String 取下标及性能问题 取下标 String String 用 String.Index 取下标(subscript)得到 Character,String.Index 要从 ...
 - java.lang.StringIndexOutOfBoundsException: String index out of range: 0
		
hibernet 报错 java.lang.StringIndexOutOfBoundsException: String index out of range: 0 处理方法 数据表字段为char ...
 - Spring Boot 启动报错 Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: 37
		
使用命令 java -jar springBoot.jar 启动项目,结果报错如下: Exception at java.lang.String.substring(String.java:) at ...
 - IndexError:string index out of range
		
IndexError:string index out of range 出现在下标越界的情况,如 item[1],可能为空的时候下标就会越界
 - hibernate  createSQLQuery  StringIndexOutOfBoundsException: String index out of range: 0
		
有一个sql用union拼接的如下: select id,(**还有很多字段**),'' as NewName from tb1 union select id,(**还有很多字段**),name a ...
 - mac安装MySQLdb:IndexError: string index out of range
		
使用mac安装MySQLdb的时候出现string index out of range 大概的错误是这样的: 然后尝试手动安装,我下载了包后,依然出现这个错误. 于是百度了下: https://ww ...
 - tk.mybatis 报错:tk.mybatis.mapper.MapperException: tk.mybatis.mapper.MapperException: java.lang.StringIndexOutOfBoundsException: String index out of range: -1
		
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'apiLogMapper ...
 - [Swift]字符串(String类、NSString类)常用操作
		
NS是Cocoa类对象类型的前缀,来源于乔布斯建立的另一家公司--NeXTNSString的使用方法,和Swift语言中的String有很多相似之处. 1.字符串的定义String类 var str1 ...
 - Swift 01.String
		
1.字符串拼接 var num1 = "hello,world" var name = "xiaoming" var age = let student = n ...
 
随机推荐
- 设计模式 Mixin (混入类)
			
混入(mix-in)类代表类之间的另一种关系.在C++中,混入类的语法类似于多重继承,但是语义完全不同.混入类回答"这个类还可以做什么"这个问题,答案经常以"-able& ...
 - If one session has a shared or exclusive lock on record R in an index, another session cannot insert
			
If one session has a shared or exclusive lock on record R in an index, another session cannot insert ...
 - latch介绍
			
latch是一种锁,用来实现对Oracle所有共享数据结构的串行化访问.共享池就是这样一个例子, 这是系统全局区中一个庞大的共享数据结构,Oracle正是在这里存储已解析,已编译的SQL. 修改这个共 ...
 - HDU Collect More Jewels 1044
			
BFS + 状态压缩 险过 这个并不是最好的算法 但是写起来比较简单 , 可以AC,但是耗时比较多 下面是代码 就不多说了 #include <cstdio> #include <c ...
 - 检测CPU是否支持虚拟化
			
一:下载检测软件 地址:http://files.cnblogs.com/hongmaju/Coreinfo.rar 二:使用方法 打开运行窗口,找到Coreinfo.exe,运行如下: 现在你要做的 ...
 - 动态规划——E (LIS())最长上升子序列
			
E - LIS Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Submit Stat ...
 - Registering Shell Extension Handlers
			
最近在做Windows shell extension 的开发工作,对shell extension handler的注册机制有点疑问,以下摘自MSDN:http://msdn.microsoft.c ...
 - 意大利进口的衬衫面料pH值严重超标·都市快报
			
意大利进口的衬衫面料pH值严重超标·都市快报 意大利进口的衬衫面料pH值严重超标 董捷 2007-03-24 通讯员 浙 检 记 者 董 捷 ...
 - Tomcat Server Locations
 - TestNG关键字和testNG.xml结构学习
			
转自官网:http://testng.org/doc/documentation-main.html#test-results TestNG关键字 @BeforeSuite@AfterSuite@Be ...