Skip to content

Commit

Permalink
Merge pull request #6522 from allbertoMD/Reto-#11
Browse files Browse the repository at this point in the history
#11-Swift
  • Loading branch information
Roswell468 authored May 12, 2024
2 parents 9f558b2 + 20d599a commit de626b8
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions Retos/Reto #11 - URL PARAMS [Fácil]/swift/allbertoMD.swift
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)

0 comments on commit de626b8

Please sign in to comment.