-
-
Save fitomad/c4639f21eea9b55660f80461c553ffe3 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
/* | |
Las funciones drop, al no estar marcadas | |
como `mutating`, dejan el String como está. | |
Se limitan a crear un nuevo String a partir del original | |
quitando los caracteres indicados | |
*/ | |
import Foundation | |
let numeroTelefono: String = "+34555_111_222" | |
// Crea un nuevo String quitando el primer caracter. | |
let numeroSinSimbolo: String = String(numeroTelefono.dropFirst()) | |
print(numeroSinSimbolo) | |
/* | |
34555_111_222 | |
*/ | |
// Crea un nuevo String quitando los 3 primero caracteres. | |
let numeroSinPrefijo: String = String(numeroTelefono.dropFirst(3)) | |
print(numeroSinPrefijo) | |
/* | |
555_111_222 | |
*/ | |
// Crea un nuevo String quitando el último caracter. | |
let cambioUltimo: String = String(numeroTelefono.dropLast()) | |
print(cambioUltimo) | |
/* | |
+34555_111_22 | |
*/ | |
// Crea un nuevo String quitando los 3 últimos caracteres. | |
let cambioAlFinal: String = String(numeroTelefono.dropLast(3)) | |
print(cambioAlFinal) | |
/* | |
+34555_111_ | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment