rustrust string concat
Rust strings can be concatenated using the +
operator. For example:
let s1 = "Hello";
let s2 = "World";
let s3 = s1 + " " + s2;
The output of the above code is:
Hello World
The +
operator can be used to concatenate two strings, or a string and a string literal. The format!
macro can also be used to concatenate strings, and it allows for more complex string formatting.
Code explanation
let s1 = "Hello";
: This line declares a string variables1
and assigns it the value"Hello"
.let s2 = "World";
: This line declares a string variables2
and assigns it the value"World"
.let s3 = s1 + " " + s2;
: This line concatenates the stringss1
ands2
with a space in between, and assigns the result to the variables3
.format!
macro: This macro allows for more complex string formatting and concatenation.
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...