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?
9 Answers
+ 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.
+ 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);
+ 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);
+ 1
Great đ
0
print("GOOGLE.COM")
0
I got new error man
0
Already solved it man
0
Thank you for telling push method in rust
0
Now my password generator project is finished