2 ms·
You can pretty much do this in Rust: let simple_str: &[u8] = b"hello world"; println!("{}", simple_str[6] as char); // 'w' Though I would advise against
by brundolf 6y ago
You can pretty much do this in Rust:
let simple_str: &[u8] = b"hello world";
println!("{}", simple_str[6] as char); // 'w'
Though I would advise against it in most cases, because even many "non-human" formats like XML and JSON do allow for Unicode characters
- sedatk 6y agoFilenames too.
- alkonaut 6y agoThere is no problem making filenames that are bound ascii. Just because they can be non-ascii on most OS'es, doesn't mean they are (when I myself control all input - that's the key). I think it's the problem of generality here. If I make a game that has thousands of texture files I want to store in a lookup table and it saves me x ns on the lookup if those textures are in a dictionary with 1-byte characters vs 2-byte character keys, then I could just make sure my file names are ascii. So I have a collection of 2000 ascii file names. I don't care whether the rest of the files outside my game textures are, or could be, non-ascii.
- Narishma 6y agoYou shouldn't be using strings in that case anyway, especially if performance matters.