update
This commit is contained in:
18
String_manipulation/rust/Cargo.lock
generated
18
String_manipulation/rust/Cargo.lock
generated
@@ -2,6 +2,24 @@
|
||||
# It is not intended for manual editing.
|
||||
version = 4
|
||||
|
||||
[[package]]
|
||||
name = "autocfg"
|
||||
version = "1.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c08606f8c3cbf4ce6ec8e28fb0014a2c086708fe954eaa885384a6165172e7e8"
|
||||
|
||||
[[package]]
|
||||
name = "rust"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"substring",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "substring"
|
||||
version = "1.4.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "42ee6433ecef213b2e72f587ef64a2f5943e7cd16fbd82dbe8bc07486c534c86"
|
||||
dependencies = [
|
||||
"autocfg",
|
||||
]
|
||||
|
||||
@@ -4,3 +4,4 @@ version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
substring = "1.4.5"
|
||||
@@ -11,41 +11,7 @@
|
||||
/* --------------------------------------------- 100 -------------------------------------------- */
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// use substring::Substring;
|
||||
|
||||
|
||||
|
||||
@@ -56,5 +22,77 @@
|
||||
|
||||
|
||||
fn main() {
|
||||
println!("Hello, world!");
|
||||
|
||||
let text = "Hello, world! How are you?";
|
||||
// let mut count = 1;
|
||||
// let textlength = text.len();
|
||||
let mut wordlist: Vec<String> = vec![];
|
||||
let mut word = String::new();
|
||||
|
||||
|
||||
// Loop through characters directly
|
||||
for c in text.chars() {
|
||||
if c != ' ' { // Use char, not string
|
||||
word.push(c); // push works with char
|
||||
} else {
|
||||
println!("word {word}");
|
||||
wordlist.push(word.clone());
|
||||
word.clear();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
println!("{:?}", wordlist); // Works
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// // loop over each character in text
|
||||
// while count > textlength {
|
||||
// let start_index = count - 1;
|
||||
// let char = text.substring(start_index, count);
|
||||
|
||||
// if char != " " {
|
||||
// word.push_str(char);
|
||||
// }
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user