rustrust string add string
Rust strings are a type of data structure used to store and manipulate text. They are stored as a sequence of Unicode scalar values, which are numbers that represent characters. Strings can be added together using the +
operator.
Example code
let s1 = "Hello";
let s2 = "World";
let s3 = s1 + " " + s2;
println!("{}", s3);
Output example
Hello World
The code above creates two strings, s1
and s2
, and then adds them together using the +
operator. The result is stored in s3
, which is then printed out.
Code explanation
let s1 = "Hello";
: This creates a string calleds1
and assigns it the value"Hello"
.let s2 = "World";
: This creates a string calleds2
and assigns it the value"World"
.let s3 = s1 + " " + s2;
: This addss1
ands2
together, separated by a space, and stores the result ins3
.println!("{}", s3);
: This prints out the value ofs3
.
Helpful links
More of Rust
- How to use regex to match a double quote in Rust?
- How to use regex to match a group in Rust?
- How to parse JSON string in Rust?
- How to use a HashBrown with a Rust HashMap?
- How to replace a capture group using Rust regex?
- How to replace all matches using Rust regex?
- How to convert a Rust slice to a fixed array?
- How to map an array in Rust
- How to split a string with Rust regex?
- How to use non-capturing groups in Rust regex?
See more codes...