I am attempting to index a string in Rust, but the compiler throws an error. My code (Project Euler problem 4, playground):
fn is_palindrome(num: u64) ->
You can convert a String or &str to a vec of a chars and then index that vec.
String
&str
vec
For example:
fn main() { let s = "Hello world!"; let my_vec: Vec = s.chars().collect(); println!("my_vec[0]: {}", my_vec[0]); println!("my_vec[1]: {}", my_vec[1]); }
Here you have a live example