Swift-3-字符串和字符

// Playground - noun: a place where people can play



import UIKit



var 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 = 3

let message = "\(multiplier) times 2.5 is \(Double(multiplier) * 2.5)"

 

你可能感兴趣的:(swift)