Some of the use of strings in Swift

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.