rustHow do I add two strings together in Rust?
Adding two strings together in Rust is a simple process. The +
operator is used to concatenate two strings. For example:
let s1 = "Hello";
let s2 = "World";
let s3 = s1 + " " + s2;
println!("{}", s3);
This code will output Hello World
.
Code explanation
let s1 = "Hello";
- This declares a string variables1
and assigns it the valueHello
.let s2 = "World";
- This declares a string variables2
and assigns it the valueWorld
.let s3 = s1 + " " + s2;
- This declares a string variables3
and assigns it the value ofs1
concatenated with a space ands2
.println!("{}", s3);
- This prints the value ofs3
to the console.
Helpful links
More of Rust
- How to replace a capture group using Rust regex?
- How to use regex to match a group in Rust?
- How to parse JSON string in Rust?
- How to use non-capturing groups in Rust regex?
- How to implement PartialEq for a Rust HashMap?
- How to use a tuple as a key in a Rust HashMap?
- How to use regex with bytes in Rust?
- How to calculate the inverse of a matrix in Rust?
- Hashshet example in Rust
- How to ignore case in Rust regex?
See more codes...