: 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