Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,870 questions

51,793 answers

573 users

How to concatenate strings in Rust

5 Answers

0 votes
fn main() {
    let string1 = String::from("rust");
    let string2 = String::from("c c++");

    let new_string = format!("{}{}{}", string1, " ", string2);
    
    println!("{}", new_string);
}
 




/*
run:
    
rust c c++
    
*/

 



answered Oct 1, 2022 by avibootz
0 votes
fn main() {
    let mut string1 = "rust".to_string();
    let string2 = "c c++".to_string();
    
    string1.push_str(" ");
    string1.push_str(&string2);
 
    println!("{}", string1);
    println!("{}", string2);
}
 




/*
run:
    
rust c c++
c c++
    
*/

 



answered Oct 1, 2022 by avibootz
0 votes
fn main() {
    let string1 = "rust";
    let string2 = "c c++";

    let result = [string1, string2].join(" ");
    
    print!("{}", result);
}





/*
run:
    
rust c c++

*/

 



answered May 21, 2023 by avibootz
0 votes
fn main() {
    let string1 = "rust";
    let string2 = "c c++";

    let result = format!("{} {}", string1, string2);
    
    print!("{}", result);
}





/*
run:
    
rust c c++

*/

 



answered May 21, 2023 by avibootz
0 votes
fn main() {
    let string1 = "rust".to_string();
    let string2 = "c c++".to_string();

    let result = string1 + " " + &string2;
    
    print!("{}", result);
}





/*
run:
    
rust c c++

*/

 



answered May 21, 2023 by avibootz
...