rustHow to join two strings in Rust
Joining two strings in Rust can be done using the +
operator. The following ## Code example shows how to join two strings:
let string1 = "Hello";
let string2 = "World";
let joined_string = string1 + " " + string2;
println!("{}", joined_string);
Output
Hello World
Explanation:
- The
let
keyword is used to declare a variable. - The
string1
andstring2
variables are declared and assigned the strings "Hello" and "World" respectively. - The
+
operator is used to join the two strings. - The
println!
macro is used to print the joined string to the console. - The
{}
placeholder is used to specify the value of thejoined_string
variable.
Helpful links:
More of Rust
- Hashshet example in Rust
- How to convert Rust bytes to hex?
- How to convert a Rust HashMap to a JSON string?
- How to convert a Rust HashMap to JSON?
- How to get the last element of a Rust slice?
- How to use non-capturing groups in Rust regex?
- How to use groups in a Rust regex?
- How to match the end of a line in a Rust regex?
- How to escape dots with regex in Rust?
- How to use regex to match a group in Rust?
See more codes...