rustrust string b prefix
A String
in Rust is a UTF-8 encoded, growable piece of text. It can be created from a literal string or a &str
reference. The b
prefix is used to create a &[u8]
byte slice from a string literal.
Example
let byte_slice = b"Hello world!";
Output example
[72, 101, 108, 108, 111, 32, 119, 111, 114, 108, 100, 33]
The b
prefix creates a byte slice from the string literal, which is a sequence of bytes. In this example, the byte slice contains the ASCII codes for each character in the string.
Helpful links
More of Rust
- How to match whitespace with a regex in Rust?
- How to use Unicode in a regex in Rust?
- How to sleep in Rust
- How to match a URL with a regex in Rust?
- How to convert a Rust slice to a fixed array?
- How to get a capture group using Rust regex?
- How to replace a capture group using Rust regex?
- How to use regex to match a double quote in Rust?
- How to use non-capturing groups in Rust regex?
- How to use regex with bytes in Rust?
See more codes...