SWIFT3-Use of strings

Source: Internet
Author: User
Tags locale

Swift related knowledge, have time to knock points, for their own learning summary, or also fortunate to help others, there is understanding, the use of the wrong place also hope to be corrected.

///***********************************************************************************************************/

2016.12.23

///***********************************************************************************************************/

Swift3, simple use of strings, directly paste the code over, more convenient to view

//Strings StringFunc stringtest ()Void {//String DefinitionsLet str1 ="Yiyi"Let str2="2222"var str3= String ()//empty stringvar STR4 =""//empty string//character Fu Dingyi (one for characters)Let Char1:character ="D"                //string Lengthvar strcount =Str1.characters.count Strcount= Str1.lengthofbytes (using: String.Encoding.utf8) print (String (format:"Strcount = ="), Strcount)//string Conversion integerPrint ((str2 asnsstring). IntegerValue)//string concatenationSTR3 = str1 +str2//STR3 = "\ (str1) \ (str2)"//STR3 = globalstr + String (str1)Print (String (format:"STR3 = ="), STR3)//string and character stitching//STR4 = str1+string (char1)STR4 ="\ (str1) \ (char1)"STR4= Str1.appending (String (CHAR1))//other types Convert string string () exp:string (strcount)Print (String (format:""), STR4)//concatenation of strings and other types of valuesLet Int1 =TenLet int2=11.1Let STR5= String (format:"%i%.1f", Int1,int2) print (String (format:"STR5 = ="), STR5)//string enumeration iterates through each characterLet S1 ="Hello world!"        ifStrcount! =0{print ("determine if string length is not 0, not empty")        }         forCinchs1.characters {print (c)}//string comparisonLet SS1 ="Hello"Let ss2=", Banana"var ss3= ss1+SS2ifSS1 = =SS2 {print ("Ss1=ss2")        }        ifSs1+ss2 = =SS3 {print ("SS1+SS2=SS3")        }        ifSs1 > SS2 {//h is greater than BPrint"Ss1>ss2")        }        //determines whether a string contains a string        if(SS3. Range (OF:SS1)! =Nil) {Print ("string containing substrings")        }        //String CasePrint (ss3.uppercased ())//Hello,bananaPrint (ss3.capitalized)//Hello,bananaPrint (ss3.lowercased ())//Hello,banana        /*//These two usages do not understand print (ss3.uppercased (With:locale (identifier: "L")))//Hello,banana print (Ss3.low Ercased (With:locale (identifier: "O")))//Hello,banana*/                        //Truncate clipping stringPrint (Ss3.substring (From:ss3.characters.index (of:",")!))//, banana intercepts the string from "," to startPrint (Ss3.substring (To:ss3.characters.index (of:",")!))//Hello Intercept string to "," EndPrint (Ss3.unicodescalars[ss3.unicodescalars.startindex. < Ss3.unicodeScalars.index (of:",")!]);//HelloPrint (Ss3[ss3.index (Ss3.startindex, Offsetby:4)])//O take a character from a stringSs3.remove (At:ss3.characters.index (of:",")!)//remove special characters from a stringPrint (SS3)//Hellobanana            }

SWIFT3-Use of strings

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.