Swift learns-----strings

Source: Internet
Author: User

string*Swift's string type is seamlessly bridged with the Foundation NSString class*the strings in the OC language are also terminated with a, Swift is not*The string in OC is an object, and Swift uses string as a struct, which is more efficient and supports traversal attention* Swift's string type is a value type. If you create a new string, then it is a constant, variable assignment operation, or a function/when passed in a method, a value copy is made. In any case, a new copy of the existing string value is created and the new copy is passed or assigned to let STR="SC\0lnj" forChinchstr.characters {print (ch)}//Stitchingvar str1 ="SSC"var str2="NX"str1+=STR2STR1//interpolated ValuesLet name ="SSC" let Age= toLet result="name = \ (name), age = \ (age)"//Formatting//01.png//02.png//...//10.png forIinch 0...5{let name= String (format:"%02d.png", arguments: [i]) print (name)}//InterceptLet STR3 ="com.baidu.www"//Intercept XMG//Note: Methods for intercepting strings in Swift, receiving parameters that are not the same as in OC//early, for everyone to develop convenient, proposed conversion to nsstring after interception//ConversionLet STR4 = Str3 asNsstringlet result2= Str4.substringfromindex (Ten)//The . StartIndex in the swift string that is used to get the position of the first character in a string//The . EndIndex in the swift string that gets the position of the last string ' Next ' in the stringLet RESULT3 = Str3.substringfromindex (Str3.endIndex.advancedBy (-3)) Let Result4= Str3.substringfromindex (Str3.startIndex.advancedBy (Ten))

Swift learns-----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.