Interpolate in a string
var " Hello " 6var"hello \ (i)"
Accumulate strings
var " Hello " 6var"hello \ (i)"
Inserting a single value character with a function
var " fdasf " Aaa.insert ("C", AtIndex:aaa.startIndex)
Inserting multiple characters with a function
var str="addfsd" str.insertcontentsof ("Adsdas ". Charaters,at:str.startindex)
Some of the use of strings
var str= "Hello word"
Str.characters.count//output string size Str.startindex//First subscript Str[str.startindex]//First letter Str.endindex// The last subscript str.startIndex.successor (). Successor ()//successor () represents the next Str.startIndex.successor (). predecessor ()// Predecessor () represents the previous str.startIndex.successor (). Advancedby (-1)//Advancedby indicates an increase in Str.substringfromindex (Str.startIndex.advancedBy (2) //From what began to intercept to the last Str.substringtoindex (Str.endIndex.advancedBy (-3)) //from start to what let ran= Range (Start:str.startIndex.successor (), End:str.startIndex.advancedBy (3)//define a range Str.substringwithrange (RAN)//intercept range valuesvarSTR3 ="a C"str3[str3.startindex.successor ()]//Original AC is a picture, is a smiley face, is to reflect why can not use subscript access, should be the following table do not know how much position
Arrays in Swift
varmyset:set<int> = [1,2,3,3] //duplicate will overwrite vararr=[1,2,3] //equivalent to array arrays
Ordered so you can use subscript to access arr[0] varDIC = [1:"a",2:"b"] //Want to HashMap forItemincharr{Print (item)} for(Index,value)incharr.enumerate () {print ("index is \ (index) value is \ (value)")} //Display the subscript and value of the array for(Key,value)inchdic{Print ("key is \ (key) value is \ (value)")} forKinchdic.keys{Print ("key is \ (k)")} //Output key only forVinchdic.values{Print ("key is \ (v)")} //Output only value //all are value types except that arr is unordered,
Some of the use of strings in Swift