© Yanis Zafirópulos 2019
Yanis ZafirópulosSwift 4 Recipeshttps://doi.org/10.1007/978-1-4842-4182-0_7

7. Strings

Yanis Zafirópulos1 
Granada, Spain

In programming, a string is a way of referring to a sequence of characters, either as a literal constant or as a variable. Swift provides us with lots of functions to interact with them. In this chapter, we will dive into the Swift library for Strings and explore different ways to manipulate them efficiently.

7.1 Append character to string


I want to append a character to an existing string.


Let’s initialize our Character.
let char : Character = "!"
First approach: Using the += operator.
var first = "Hello World"
first += String(char)
Second approach: Using the append method .
var second ...

Get Swift 4 Recipes: Hundreds of Useful Hand-picked Code Snippets now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.