varsample="Hello"
sample +=" World" // sample == "Hello World"
sample.append("!") // sample == "Hello World!"letname="Marie Curie"letfirstSpace= name.firstIndex(of:"")?? name.endIndex
letfirstName=name[..<firstSpace] // firstName == "Marie"
import Foundation // necessary
letstring="Swift"print(string.contains("ft")) // true
print(string[string.index(string.startIndex, offsetBy:4)]) // tletchar="A"UnicodeScalar(char)!.value // 65 : UInt32
letnumber=String(10, radix:2) // you can add uppercase: Bool
print(number) // number : String = 1010
import Foundation // necessary
varid="super..power"
id = id.replacingOccurrences(of:"..", with:".") // id == "super.power"
varname="edkward"letwrongPosition= name.firstIndex(of:"k")
name.remove(at: wrongPosition!) // name == edward
name.removeFirst() // name == dward
name.removeLast() // name == dwar
import Foundation // necessary
varname="(hermione)))))"
name = name.trimmingCharacters(in:["(",")"]) // in : CharacterSet
// name == hermioneletnum=5print(String(format:"%02d", num)) // 05
func isMatched(target:String, pattern:String)->Bool{letpatternString="^"+ pattern.replacingOccurrences(of:"*", with:"[a-zA-Z0-9]")+"$" // "^": start, "$": end
letregex=try?NSRegularExpression(pattern: patternString)return regex?.firstMatch(in: target, options:[], range:NSRange(location:0, length: target.count))!=nil}