-
-
Save fitomad/239bfb214c2488ba372befef7b5278ec to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var texto: String = " de cuyo nombre no quiero acordarme " | |
let antes: String = "En un lugar de Mancha" | |
let despues: String = "no ha mucho tiempo que vivía" | |
// Insertamos al principio | |
texto.insert(contentsOf: antes, at: texto.startIndex) | |
print("1. \(texto)") | |
// Insertamos al final | |
texto.insert(contentsOf: despues, at: texto.endIndex) | |
print("2. \(texto)") | |
// Insertamos a mitad del String. | |
// Tenemos que corregir el texto para que en lugar de | |
// *..lugar de Mancha...* sea lea *..un lugar de la Mancha...* | |
if let index: String.Index = texto.index(of: "M") | |
{ | |
texto.insert(contentsOf: "la ", at: index) | |
print("3. \(texto)") | |
} | |
/* | |
1. En un lugar de Mancha de cuyo nombre no quiero acordarme | |
2. En un lugar de Mancha de cuyo nombre no quiero acordarme no ha mucho tiempo que vivía | |
3. En un lugar de la Mancha de cuyo nombre no quiero acordarme no ha mucho tiempo que vivía | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment