字符串基本使用:
1. 定义字符串变量
var string = "hello"```
#####2. 创建空字符串变量(两者等价)
var string1 = ""
var string2 = String()```
3. 判断空字符串 , 通过 .isEmpty 方法
if(string1.isEmpty){
print("String is empty")
}```
#####4. 字符串拼接 += 方法
var string3 = "http://"
string3 += "www.baidu.com"
print(string3)```
5. 获取字符串长度
let length = string3.characters.count
print("length = ", length)
6. 字符串比较
let name1 = "abc"
let name2 = "def"
if(name1 == name2){
print("\(name1) equals \(name2)")
}else{
print("不同")
print("\(name1) equals \(name2)")
print(name1, "equals", name2)
}```
#####7. 插值
let num = 3.0
let newNum = "(num) * 2.5 = (num * 2.5)"
print(newNum)
print(num ,"* 2.5 = ", num * 2.5)```