In C, we can operate a string by index like this char str = “abcde”; str[i] … … or by pointer; Is there a similar mechanism in Rust? If not, how to operate a string in Rust?
You can’t do that with strings in rust, because the components are not of fixed size, so it does not behave like an array. You can create a
Vec<char> if you want to use it like an array. NB Rust
char is not the same thing as a C
thx, and if I write a string like this: let s = “A STRING”.to_string(); then I use: s.as_slice() , does it mean ‘s’ itself is converted to &str type? or I only get a &str copy of ‘s’?
Please use Stack Overflow to ask these kinds of questions. This forum is for discussion about the development of the language itself, not using it.
This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.