What are the string and Character Types of Swift ?? Provides a fast and Unicode-compatible way to process code.
String constant
let strTest = "I‘m Swift"
String null value judgment
let emptyString = ""if emptyString.isEmpty {2. println("Nothing to see here")3. }
String variability. The variability of the string is determined by VAR or let. VaR indicates variable strings, and let indicates constant strings.
var strMsg = "test message"strMsg = "reset message"let strConst = "msg const"
String concatenation string supports the plus (+) and minus (+ =) operations.
var strMsg = "msg "let strConst = "const "strMsg = strMsg + strConststrMsg += "endl"println("\(strMsg)")
String is a collection of single Unicode characters character
For char in "TST ** Han" {println ("\ (char) \ n ")}
Number of string characters. Use the countelements Function
VaR strtest = "C plug is te" println ("\ (countelements (strtest ))")
String comparison provides three methods to compare string values: equal strings, equal prefixes, and equal suffixes. String =
Hasprefix/hassuffix method to check whether the string has a specific prefix/suffix
VaR strtest = "C plug is te" Var strsecond = "C plug is te" If strtest = strsecond {println ("same");} If strtest. hassuffix ("te") {println ("has SUF ");}
String case-sensitive version
Returned by uppercasestring and lowercasestring of the string
Let normal = "Hello, Ketty! Hello "Var shouty = normal. uppercasestringvar whispered = normal. lowercasestringprintln (" \ (shouty) \ n \ (Whispered) ") // output hello, Ketty! Hello, Ketty! Hi!
Character Type Declaration
Let chtest: character = "" // here is double quotation marks.