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 parse a file with Rust regex?
- How to use regex to match a double quote in Rust?
- How to replace a capture group using Rust regex?
- How to use non-capturing groups in Rust regex?
- Regex example to match multiline string in Rust?
- How to use regex lookbehind in Rust?
- How to match the end of a line in a Rust regex?
- How to use regex captures in Rust?
- How to replace all using regex in Rust?
- How to match whitespace with a regex in Rust?
See more codes...