rustrust string chars
A String in Rust is a UTF-8 encoded sequence of bytes. It is a collection of characters, and each character is represented by a char type.
let s = String::from("Hello, world!");
for c in s.chars() {
println!("{}", c);
}
The output of the above code is:
H
e
l
l
o
,
w
o
r
l
d
!
The chars() method of a String returns an iterator over the characters of the string. This iterator can be used to iterate over the characters of the string.
The char type in Rust is a Unicode scalar value, which means it can represent a code point in any Unicode code point range.
Helpful links
More of Rust
- Regex example to match multiline string in Rust?
- How to use regex lookahead in Rust?
- How to create a Rust regex from a string?
- How to use regex with bytes in Rust?
- How to use regex to match a double quote in Rust?
- Bitwise operator example in Rust
- How to use regex lookbehind in Rust?
- How to use captures_iter with regex in Rust?
- How to use regex to match a group in Rust?
- How to insert an element into a Rust HashMap if it does not already exist?
See more codes...