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
s1ands2with the valuesHelloandWorldrespectively. - Concatenates the two strings using the
+operator and assigns the result tos3. - Prints the value of
s3to the console.
For more information on string concatenation in Rust, please refer to the following links:
More of Rust
- How to use regex to match a double quote in Rust?
- How to create a HashMap of structs in Rust?
- How to replace a capture group using Rust regex?
- How to match the end of a line in a Rust regex?
- How to modify an existing entry in a Rust HashMap?
- How do I identify unused variables in Rust?
- How to use negation in Rust regex?
- Regex example to match multiline string in Rust?
- How to use a Rust HashMap in a struct?
- How do I use a variable number of arguments in Rust?
See more codes...