append a string in swift

To append a string in Swift, you can use the + operator or the += operator. Here's an example of using the += operator:

main.swift
var myString = "Hello"
myString += " World"
print(myString) // Output: "Hello World"
85 chars
4 lines

You can also use the append(_:) method to append a single character at a time, like this:

main.swift
var myString = "Hello"
myString.append("!")
print(myString) // Output: "Hello!"
80 chars
4 lines

And finally, you can use string interpolation to concatenate a string value with other variables, like this:

main.swift
var firstName = "John"
var lastName = "Doe"
var fullName = "\(firstName) \(lastName)"
print(fullName) // Output: "John Doe"
124 chars
5 lines

gistlibby LogSnag