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 get a capture group using Rust regex?
- How to convert a Rust slice to a tuple?
- How to use regex to match a double quote in Rust?
- How to implement PartialEq for a Rust HashMap?
- How to create a HashMap of structs in Rust?
- How to use Unicode in a regex in Rust?
- How to replace a capture group using Rust regex?
- How to match a URL with a regex in Rust?
- How to replace all matches using Rust regex?
See more codes...