That's unnecessarily expensive. Why take the owned strings, get their underlying slice, and then copy the whole thing with an extra allocation for each?
If one already has a
Vec<String>, the following works:
let argv: Vec<String> = env::args().collect();
let byte_i_j = argv[i].as_bytes()[j];
However, this is probably not what OP wants.
@moon548834, am I guessing right that you are trying to parse the command line arguments? Be aware that string bytes aren't equivalent to "characters" because Rust supports Unicode and
Strings are always encoded as UTF-8. Depending on your definition of a "character", you might be looking for
str::chars() (which gives you Unicode code points) or
UnicodeSegmentation::graphemes() (this one gives you grapheme clusters), neither of which can possibly provide random access indexing, because UTF-8 and Unicode in general are variable-length encodings at multiple levels.
TL;DR: If you just want to parse command-line arguments easily, check out some dedicated crates such as structopt, docopt, clap, getopts (for a less sophisticated but more traditional alternative), or some of the several other command line utility crates.