C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
Swift program that combines two strings
// Two string literals.
let value = "cat "
let value2 = "and dog"
// Combine (concatenate) the two strings.
let value3 = value + value2
print(value3)
Output
cat and dog
Also: The append() func can be used to add a character on the end of an existing string.
Swift program that appends to string
// This string can be changed.
var value = "one"
// Append data to the var string.
value += "...two"
print(value)
Output
one...two
Tip: To specify an interpolated variable, use an escaped parenthesis. Then specify the variable name.
Swift program that uses string interpolation
let name = "dotnetCodex"
let id = 100
// Use string interpolation.
// ... Create a string with variable values in it.
let result = "Location: \(name), ID: \(id)"
print(result)
Output
Location: dotnetCodex, ID: 100