Define an empty string
var str1 = ""
var str2 = String ()
Str1.isempty//Judging if the string is empty
All characters in the output string
var str3 = "As God name"
For C in str3{
println (c)
}
Maximum value of type int.max//int
Minimum value of type int.min//int
var arr1 = ["C", "OC", "ios", "Swift"]
var count = 0
For name in arr1{
If Name.hasprefix ("I") {//Hasprefix prefix
count++
Count
}
}
Count = 0
For name in arr1{
If Name.hassuffix ("s") {//Hassuffix suffix
count++
Count
}
}
var string1:string = "Hello, swift!!"
var string2 = "As God name"
Uppercasestring lowercasestring
String2.uppercasestring
String2.lowercasestring
Trim removes whitespace before and after a string
String1.stringbytrimmingcharactersinset (Nscharacterset.whitespaceandnewlinecharacterset ())
String1.stringbytrimmingcharactersinset (Nscharacterset (charactersinstring: "H"))
Split
String2.componentsseparatedbystring ("")
var string3 = "Welcome to play swift! Step-by-Step learn from Now "
String3.componentsseparatedbycharactersinset (Nscharacterset (charactersinstring: "-"))
Join
var String4 = "-"
String4.join (["One", "one", "one", "three"])
var string5 = "--"
var arr = ["ios", "Swift", "OC"]
String5.join (arr)
var str = "Welcome to play swift! Step by step Learn Swift language
Range
Str.rangeofstring ("Step")
Str.rangeofstring ("Step", Options:NSStringCompareOptions.BackwardsSearch)
Str.rangeofstring ("Welcome", Options:NSStringCompareOptions.CaseInsensitiveSearch)
Str.startindex
Str.endindex
Countelements (str)
var str = "Hello, playground"
Let Strrange = range<string.index> (Start:str.startIndex, End:str.endIndex)
Swift--Define an empty string Hasprefix hassuffix trim split join range