-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c0a3b10
commit 20d599a
Showing
1 changed file
with
42 additions
and
0 deletions.
There are no files selected for viewing
42 changes: 42 additions & 0 deletions
42
Retos/Reto #11 - URL PARAMS [Fácil]/swift/allbertoMD.swift
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import Foundation | ||
|
||
let url = "https://retosdeprogramacion.com?year=2023&challenge=0" | ||
//var parameters: [Int] = [] | ||
|
||
|
||
func extractParameters(from url: String) -> [Int] { | ||
var parameters: [Int] = [] | ||
var currentNumberString = "" | ||
|
||
for char in url { | ||
// Verificamos si el caracter es un dígito numérico | ||
if char.isNumber { | ||
// Si es un dígito, lo agregamos al string temporal | ||
currentNumberString.append(char) | ||
} else { | ||
// Si el caracter no es un dígito, verificamos si hay un número en el string temporal | ||
if !currentNumberString.isEmpty { | ||
// Si hay un número en el string temporal, lo convertimos a entero y lo agregamos al array | ||
if let number = Int(currentNumberString) { | ||
parameters.append(number) | ||
} | ||
// Reiniciamos el string temporal para el próximo número | ||
currentNumberString = "" | ||
} | ||
} | ||
} | ||
|
||
// Verificamos si hay un número pendiente en el string temporal | ||
if !currentNumberString.isEmpty { | ||
// Si hay un número pendiente, lo convertimos a entero y lo agregamos al array | ||
if let number = Int(currentNumberString) { | ||
parameters.append(number) | ||
} | ||
} | ||
|
||
return parameters | ||
} | ||
|
||
let numbers = extractParameters(from: url) | ||
print("Números encontrados en la URL:", numbers) | ||
|