rustHow to concat strings in Rust
Strings in Rust can be concatenated using the +
operator. The following ## Code example shows how to concatenate two strings:
let s1 = "Hello";
let s2 = "World";
let s3 = s1 + " " + s2;
println!("{}", s3);
Output
Hello World
The code above does the following:
- Declares two strings
s1
ands2
with the valuesHello
andWorld
respectively. - Concatenates the two strings using the
+
operator and assigns the result tos3
. - Prints the value of
s3
to the console.
For more information on string concatenation in Rust, please refer to the following links:
More of Rust
- How to get a capture group using Rust regex?
- How to use Unicode in a regex in Rust?
- How to get the last element of a Rust slice?
- How to match the end of a line in a Rust regex?
- How to replace a capture group using Rust regex?
- How to use non-capturing groups in Rust regex?
- How to use an enum in a Rust HashMap?
- How to match whitespace with a regex in Rust?
- How to split a string with Rust regex?
- How to match a URL with a regex in Rust?
See more codes...