slices
This commit is contained in:
@@ -6,3 +6,4 @@ https://tinchicus.com/2022/09/26/rust-listado-del-curso-inicial/
|
||||
- https://tinchicus.com/2022/06/07/rust-vector/ (vectores)
|
||||
- https://tinchicus.com/2022/06/08/rust-tuple/ (tupla)
|
||||
- https://tinchicus.com/2022/06/09/rust-hash-map/ (mapeo)
|
||||
- https://tinchicus.com/2022/06/10/rust-slice/ (slices)
|
||||
8
slices/Cargo.toml
Normal file
8
slices/Cargo.toml
Normal file
@@ -0,0 +1,8 @@
|
||||
[package]
|
||||
name = "slices"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
16
slices/src/main.rs
Normal file
16
slices/src/main.rs
Normal file
@@ -0,0 +1,16 @@
|
||||
fn primera_palabra(s: &String) -> usize {
|
||||
let b=s.as_bytes();
|
||||
for (i,&item) in b.iter().enumerate() {
|
||||
if item == b' ' {
|
||||
return i
|
||||
}
|
||||
}
|
||||
s.len()
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let s = String::from("Hola Mundo Cruel");
|
||||
let pos=primera_palabra(&s);
|
||||
let palabra=&s[0..pos];
|
||||
println!("{}",palabra)
|
||||
}
|
||||
Reference in New Issue
Block a user