Created
April 19, 2018 09:06
-
-
Save fitomad/4b6b2f279c6dbc4fc978c2f4c13acd10 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
import Foundation | |
let texto: String = "Madrid Barcelona Bilbao Valencia Jaen Córdoba Zaragoza" | |
// Veamos si el String comienza por un String determinado | |
if texto.hasPrefix("Madrid") | |
{ | |
print("El String comienza por Madrid") | |
} | |
// Ahora si termina por un String determinado | |
if texto.hasSuffix("Zaragoza") | |
{ | |
print("La última ciudad es Zaragoza") | |
} | |
// También podemos comprobar si en algún lugar se encuentra | |
// otro String | |
if texto.contains("Bilbao") | |
{ | |
print("También aparece Bilbao") | |
} | |
/* | |
El String comienza por Madrid | |
La última ciudad es Zaragoza | |
También aparece Bilbao | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment