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
- How to match a URL with a regex in Rust?
- How to replace a capture group using Rust regex?
- How to clear a Rust HashMap?
- Yield example in Rust
- Example of yield_now in Rust?
- How to convert a Rust slice to a fixed array?
- How to use regex to match a group in Rust?
- How to convert a Rust HashMap to a BTreeMap?
- How to yield a thread in Rust?
- How to replace strings using Rust regex?
See more codes...