Rust Get Nth Char In String

[Solved] Rust Get Nth Char In String | Haskell - Code Explorer | yomemimo.com
Question : rust get nth char in string

Answered by : delightful-duck-e8k2ponp7bxk

If you want just the first char, then don't collect into a Vec<char>, just use the iterator:
let text = "hello world!";
let ch = text.chars().next().unwrap();
Alternatively, you can use the iterator's nth method:
let ch = text.chars().nth(0).unwrap();

Source : | Last Update : Tue, 23 Feb 21

Answers related to rust get nth char in string

Code Explorer Popular Question For Haskell