//: Playground-noun:a Place where people can playImport UIKit//1. Create an empty stringvarEMPTYSTR1 =""varEMPTYSTR2 = String ()//use constructors to create empty strings//determine if a string is emptyLet IsEmpty =Emptystr1.isempty//2. Concatenation of stringsvarName ="Kathy"Let height= String (" the")//(1) using interpolation symbols for stitchingLet fullstring ="\ (name) ' height is \ (height) cm"//(2) operator + overloadLet FullString2 = name +"' s height is"+ Height +"cm"//(3) calling a functionname.appendcontentsof (fullstring)//3. Comparison of stringsLet str1 ="We are logging tired"Let str2="We are logging tired"//EqualifSTR1 = =str2 {print ("str = = str2")}//whether the prefix is includedStr1.hasprefix ("We are") Str2.hassuffix ("KKK")//4. Get the characters in a stringvarLoopstr ="I am a single??" for Char inchloopstr.characters {print (Char)}//5. Get the length of a stringLoopStr.characters.count//6. Obtain a character according to the subscriptLoopstr[loopstr.startindex]//First characterLoopstr[loopstr.endindex.predecessor ()]//Loopstr.endindex: The next ordinal number at the endLoopstr[loopstr.endindex.advancedby (-5)]//7. Insert DeleteLoopstr.insert ("??", AtIndex:loopStr.endIndex) Loopstr.removeatindex (LoopStr.endIndex.advancedBy (-4) ) print (LOOPSTR)
Swift string _04_ string basic use