rustHow do I concatenate strings in Rust?
Strings in Rust can be concatenated using the + operator. For example:
let s1 = "Hello";
let s2 = "World";
let s3 = s1 + " " + s2;
println!("{}", s3);
This will output Hello World.
Code explanation
let s1 = "Hello";- This declares a string variables1and assigns it the valueHello.let s2 = "World";- This declares a string variables2and assigns it the valueWorld.let s3 = s1 + " " + s2;- This declares a string variables3and assigns it the value ofs1concatenated with a space ands2.println!("{}", s3);- This prints the value ofs3to the console.
Helpful links
More of Rust
- How to match whitespace with a regex in Rust?
- How to use Unicode in a regex in Rust?
- How to match a URL with a regex in Rust?
- How to implement PartialEq for a Rust HashMap?
- How to yield return in Rust?
- How to get the minimum value of a Rust slice?
- How to replace a capture group using Rust regex?
- Regex example to match multiline string in Rust?
- How to replace strings using Rust regex?
- How to replace all matches using Rust regex?
See more codes...