Skip to content

Latest commit

 

History

History

strings

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 

Strings:

  • storing texts or variables is known as string we use the keyword let in rust

  • main.rs

  • basic strings

fn main() {
    /* string */
    let company:&str = "CompanyOne";
    let location:&str = "Some where in the world";

    println!("company name: {} location: {}", company, location);
}
  • Illustration
fn main() {
    /* store names inside name */
    let mut name = String::new();
    name.push_str("NameOne");
    name.push_str("NameTwo");

    println!("{}", name);
}
  • Illustration: Format macro
fn main() {
    let n1 = "Name".to_string();
    let n2 = "One".to_string();

    let n3 = format!("{} {}", n1, n2);
    println!("{}", n3);
}
$ cargo run