[Swift learning] Swift programming tour-character and string (5), swift tour
String is the String type of swift. A string is a valid Character Sequence. Therefore, a character set can be expressed in combination. You can use the + symbol to connect to a string. String type is a fast and modern String implementation. Each string is composed of Unicode characters of independent encoding and supports accessing these characters in different Unicode representation. Use "" to mark strings.
I. Initialize an empty string
var emptyString = ""
var anotherEmptyString = String()
The two initialization methods are equivalent.
IsEmptyDetermines whether the current string is a null string.
if emptyString.isEmpty {
print("Nothing to see here")
}
The String type of Swift is the value type. If you create a new string value, the value is copied when it is used to assign values to constants or variables, or when it is passed in a function/method. In different cases, a new copy of an existing string value is created, and the new copy is passed or assigned a value.
Ii. Characters usage
You can use the for-in loop to access individual characters of a string.
For character in "Dog!