rustrust string concat
Rust strings can be concatenated using the + operator. For example:
let s1 = "Hello";
let s2 = "World";
let s3 = s1 + " " + s2;
The output of the above code is:
Hello World
The + operator can be used to concatenate two strings, or a string and a string literal. The format! macro can also be used to concatenate strings, and it allows for more complex string formatting.
Code explanation
let s1 = "Hello";: This line declares a string variables1and assigns it the value"Hello".let s2 = "World";: This line declares a string variables2and assigns it the value"World".let s3 = s1 + " " + s2;: This line concatenates the stringss1ands2with a space in between, and assigns the result to the variables3.format!macro: This macro allows for more complex string formatting and concatenation.
Helpful links
More of Rust
- How to match whitespace with a regex in Rust?
- How to convert a Rust slice of u8 to u32?
- Generator example in Rust
- How to match a URL with a regex in Rust?
- How to use non-capturing groups in Rust regex?
- How to pop an element from a Rust HashMap?
- How to replace all matches using Rust regex?
- How to use regex lookahead in Rust?
- How to create a HashSet from a Range in Rust?
- How to declare a constant Rust HashMap?
See more codes...