码迷,mamicode.com
首页 > 编程语言 > 详细

Swift-3-字符串和字符

时间:2014-11-23 18:54:24      阅读:191      评论:0      收藏:0      [点我收藏+]

标签:style   blog   io   ar   color   os   sp   on   div   

// 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-3-字符串和字符

标签:style   blog   io   ar   color   os   sp   on   div   

原文地址:http://www.cnblogs.com/liufeng24/p/4117177.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!