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
letkeyword is used to declare a variable. - The
string1andstring2variables 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_stringvariable.
Helpful links:
More of Rust
- How to perform matrix operations in Rust?
- How to delete an entry from a Rust HashMap?
- How to count elements in a Rust HashMap?
- How to create a new Rust HashMap with a specific type?
- How to use an enum in a Rust HashMap?
- How to escape dots with regex in Rust?
- How to create a Rust HashMap from a vec?
- Yield example in Rust
- How to match whitespace with a regex in Rust?
- How to replace strings using Rust regex?
See more codes...