Swift 2.0 Syntax string

Source: Internet
Author: User

: Playground-noun:a place where people can play

Import UIKit

/*:

String

* The string in OC is an object , and the string in Swift is a struct

* The string in OC ends with a , and the string in Swift does not end in

* string in Swift has better performance than characters in OC

* strings in Swift support traversal

*/

Let str = "Abc\0def"

Print(str)

Traversing Strings

For C in str. Characters

{

Print (c)

}

Stitching Strings

var str2 = "Lnj"

str2 + = Str

str2

Formatting

Let name = "Lnj"

Let age =

target : name = LNJ, age =

Let res = ' name ' , age= \ (age) " /c11>

2015-01-03 14:05:06

Let res2 = String(format: "%d-%02d-%02d%02d:%02d:%02d", arguments: [ 1 , 3, 5, 6])

string Interception

Let str3 = "xmg520"

Tip : If you want to intercept strings in Swift , It's best to use the methods in nsstring

Good news : most data types in Swift support Direct conversion to data types in OC . For example, String --NSString

Let res4 = (str3 as nsstring). Substringwithrange(nsmakerange(0, 3))

Let STR4: nsstring = str3

Swift 2.0 Syntax string

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.