Skip to content

Instantly share code, notes, and snippets.

@fitomad
Created April 19, 2018 10:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fitomad/c4639f21eea9b55660f80461c553ffe3 to your computer and use it in GitHub Desktop.
Save fitomad/c4639f21eea9b55660f80461c553ffe3 to your computer and use it in GitHub Desktop.
/*
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