rustrust string book
Rust strings are a powerful data type that allow for efficient storage and manipulation of text. They are stored as a sequence of bytes, and can be manipulated with a variety of methods. The Rust Book provides a comprehensive overview of Rust strings, including how to create, manipulate, and convert them.
Example code
let mut s = String::new();
s.push_str("Hello");
s.push(' ');
s.push_str("world!");
println!("{}", s);
Output example
Hello world!
The code above creates a new string, s
, and then pushes the strings "Hello" and "world!" onto it. Finally, it prints the resulting string.
The String::new()
method creates a new, empty string. The push_str()
method adds a string slice to the end of the string, and the push()
method adds a single character.
Helpful links
More of Rust
- How to implement PartialEq for a Rust HashMap?
- How to use regex with bytes in Rust?
- How to parse a file with Rust regex?
- 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 group in Rust?
- How to match the end of a line in a Rust regex?
- How to use groups in a Rust regex?
- How to find the first match in a Rust regex?
- How to check if a regex is valid in Rust?
See more codes...