reto11 finalizado

This commit is contained in:
2023-06-25 12:19:59 +02:00
parent 117cc87783
commit 0116149495
2 changed files with 32 additions and 0 deletions

View File

@@ -0,0 +1,24 @@
/*
* Dada una URL con parámetros, crea una función que obtenga sus valores.
* No se pueden usar operaciones del lenguaje que realicen esta tarea directamente.
*
* Ejemplo: En la url https://retosdeprogramacion.com?year=2023&challenge=0
* los parámetros serían ["2023", "0"]
*/
fn getparams(url: &str) -> Vec<&str> {
let url = url.split('=').collect::<Vec<&str>>();
let mut vectorsalida = Vec::<&str>::new();
for i in 1..url.len() {
// println!("url: {}", url[i].split('&').collect::<Vec<&str>>()[0]);
vectorsalida.push(url[i].split('&').collect::<Vec<&str>>()[0]);
}
vectorsalida
}
fn main() {
let parametros = getparams("https://retosdeprogramacion.com?year=2023&challenge=0");
for i in 0..parametros.len() {
println!("{}", parametros[i]);
}
}