Swift学习笔记-字符串

参考书籍:
[1]管蕾.张玲玲.朱元波.Swift开发实战[M]. 北京:人民邮电出版社.2014.10-1 ISBN 978-7-115-36827-0
[2]陈隽.刘媛媛.Swift入门很简单[M]. 北京:清华大学出版社.2015.01-01 ISBN 978-7-302-38880-7

一、字符串分类
分为两种:常量字符串和变长字符串

let 常量名=字符串字面值
let 常量名:String=字符串字面值

二、初始化

let emptystring="" //直接赋值
let emptystring=String() //String()方法
let newstring = string

三、计算字符格式

countElements()

四、字符串组合

1、运算符 + 
2、运算符 +=

五、字符串判断
1、是否为空
使用isEmpty属性,比如:

if string.isEmpty{
}

2、判断前缀
hasPrefix 判断字符串是否以某一字符串为前缀

if string.hasPrefix("H"){
}

3、判断后缀
hasSuffix 判断字符串是否以某一字符串为后缀

if string.hasSuffix("H"){
}

4、大写转化
所以小写字符转为大写字符,需要使用uppercaseString属性

str=string.uppercaseString

5、小写转化
所以大写字符转为小写字符,需要使用lowercaseString属性

str=string.lowercaseString

五、Unicode编码
记不住,等用的时候再看