Swift string _04_ string basic use

Source: Internet
Author: User

//: 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

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.