From f64b473e2dd2a85b5166093382e751dfda8ec371 Mon Sep 17 00:00:00 2001 From: narawat Date: Tue, 28 Apr 2026 14:05:55 +0700 Subject: [PATCH] update --- String_manipulation/rust/Cargo.lock | 18 +++++ String_manipulation/rust/Cargo.toml | 1 + String_manipulation/rust/src/main.rs | 110 ++++++++++++++++++--------- 3 files changed, 93 insertions(+), 36 deletions(-) diff --git a/String_manipulation/rust/Cargo.lock b/String_manipulation/rust/Cargo.lock index b9d42e1..8272c70 100644 --- a/String_manipulation/rust/Cargo.lock +++ b/String_manipulation/rust/Cargo.lock @@ -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", +] diff --git a/String_manipulation/rust/Cargo.toml b/String_manipulation/rust/Cargo.toml index 1c61e9e..fd52fcf 100644 --- a/String_manipulation/rust/Cargo.toml +++ b/String_manipulation/rust/Cargo.toml @@ -4,3 +4,4 @@ version = "0.1.0" edition = "2024" [dependencies] +substring = "1.4.5" \ No newline at end of file diff --git a/String_manipulation/rust/src/main.rs b/String_manipulation/rust/src/main.rs index ae709fa..a3611f1 100644 --- a/String_manipulation/rust/src/main.rs +++ b/String_manipulation/rust/src/main.rs @@ -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 = 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); + // } + + + + + + + + + + + + + + + } + + + + + + + + + + + + + + + + + +