reto11 finalizado
This commit is contained in:
8
ejercicios/reto11/Cargo.toml
Normal file
8
ejercicios/reto11/Cargo.toml
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
[package]
|
||||||
|
name = "reto11"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
24
ejercicios/reto11/src/main.rs
Normal file
24
ejercicios/reto11/src/main.rs
Normal 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]);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user