swift中运算符基本基础于c,下面我就给大家白话白话那些被优化过的运算符们
//加号减号的妙用 var a=1 var b= -a//此时b=-1 var c = +b//此时 c=-1 var d= - c//此时 d=1
操作符
//操作符(数字...数字1)表示从数字到数字1之间的数其中包括数字和数字1 for var i in 1...5{ printlin("数字:\(i)进化后:\(i*6)") } /*输出 数字:1进化后:6 数字:2进化后:12 数字:3进化后:18 数字:4进化后:24 数字:5进化后:30 */
swift里面用到的字符串默认都是utf-16字符编码,无论是标识符还是自定义字符串
字符串拼接用加号(+)
字符串遍历用for...in
//字符串拼接 var a="Hello" var b="world" var c=" " println(a+c+b)//输出Hello World println(a+b)//输出HelloWorld //字符串遍历 for i in a{ print("\(i) ")//输出:H e l l o } //获取字符串长度countElements print(countElements(a))//5 //字符串赋值 “let wiseWords = "\"Imagination is more important than knowledge\" - Einstein" // "Imagination is more important than knowledge" - Einstein let dollarSign = "\x24" // $, Unicode scalar U+0024 let blackHeart = "\u2665" // ♥, Unicode scalar U+2665 let sparklingHeart = "\U0001F496" //