0

[SOLVED] How to select specific string in rust

let numbers = "1234567890"; I want to select 4 in that variable how to do that in rust?

12th Feb 2022, 5:23 AM
EsaKurniawan
9 ответов
+ 1
If you know you want "4", why the elaborate scheme to get it? In other words: what are you really up to? ;) The more we know about what you want to achieve the better we can help.
12th Feb 2022, 7:54 AM
Ani Jona 🕊
Ani Jona 🕊 - avatar
+ 1
//this is the code let mut password: String = "".to_owned(); // characters let upper_case = "PYFGCRLAOEUIDHTNSJKXBMWV"; let lower_case = "pyfgcrlaoeuidhtnsjkxbmwv"; let numbers = "0123456789"; for i in 0..21 { // get random number let mut rng = thread_rng(); let select_random_char = rng.gen_range(0..lower_case.chars().count()); let result = lower_case.chars().nth(select_random_char).unwrap(); password += result; }; // print password println!("{}", password);
12th Feb 2022, 7:56 AM
EsaKurniawan
+ 1
I still don't know wherein the problem lies. It seems you have already managed to select a char out of a string. There are other problems though, such as the range you pass to gen_range, it needs to be two paramerers lower limit and upper limit. And you cannot concat a string and char. But you can push the char into the string using password.push(result);
12th Feb 2022, 8:43 AM
Ani Jona 🕊
Ani Jona 🕊 - avatar
+ 1
Great 👍
12th Feb 2022, 10:12 AM
Ani Jona 🕊
Ani Jona 🕊 - avatar
0
print("GOOGLE.COM")
12th Feb 2022, 6:46 AM
Ion Kare
Ion Kare - avatar
0
I got new error man
12th Feb 2022, 7:55 AM
EsaKurniawan
0
Already solved it man
12th Feb 2022, 9:12 AM
EsaKurniawan
0
Thank you for telling push method in rust
12th Feb 2022, 9:12 AM
EsaKurniawan
0
Now my password generator project is finished
12th Feb 2022, 9:13 AM
EsaKurniawan