首页 > 代码库 > Swift-3-字符串和字符

Swift-3-字符串和字符

// Playground - noun: a place where people can playimport UIKitvar someString = "some string literal value"someString += "another"// 初始化空字符串 2种方式,得出的结果一致var emptyString = ""var anotherEmptyString = String()if emptyString.isEmpty {    println("emptyString is empty")}// 可变字符串var varibleString = "hosrse"varibleString += "and carriage"let constantString = "hignlander"//constantString += "anything" // 字符串常量不能修改,出错// swift中字符串是值类型 value type// 连接字符串var string1 = "hello"var string2 = " there"var welcome = string1 + string2// 向字符串后添加字符let exclamationMark : Character = "!"welcome.append(exclamationMark)// 字符串插值 \()let multiplier = 3let message = "\(multiplier) times 2.5 is \(Double(multiplier) * 2.5)"

 

Swift-3-字符串和字符