Operators in Swift
Import Foundation//Character Typevar Char: Character ="a"Char="b"println (Char)varStr:stringstr="abcceadfasdfl;jk\0dfaaaa 0001496"println (str)//View length countelements the number of elements returnedprintln (countelements (str))varstr1="Hrllo"println (str1+" World")//string formatting \ (string, variable, expression)varindex="ABC"varMessage="http://www.baidu.com/tag=\ (index). PNG"println (message)//The comparison of strings is encoded, not contentLet m_s1="HeLlo"Let m_s2="Hello World"ifM_S1 = =m_s2{println ("equals")}ifM_S1 >=m_s2{println ("greater than or equal")}ifM_S1 <=m_s2{println ("less than or equal")}ifM_s1 <m_s2{println ("less than")}ifM_s1 >m_s2{println ("Greater than")}ifM_s1.hassuffix ("Lo") {println ("suffix")}ifM_s1.hasprefix ("He") {println ("prefix")}println (m_s1.lowercasestring+"Turn lowercase") println (m_s1.uppercasestring+"Turn Capital")//Type Conversionsvarn_s1="255"println (N_s1.toint ())//What you get is an optional value.//closed interval operator (A...B) for_inch(1...5){ //println ("Hello")} forIinch(1...5) {println ("Hello"+String (i))}//semi-closed interval operator (a). <B) forIinch(1.. <5) {println (i)}
Beginner Swift note operator (ii)