fn main() {
println!("Hello, world!");
}
fn main() {
let s1 = String::new();
println!("s1:{},s1's length:{}",s1,s1.len());
let s2 = String::from("hello world.");
println!("s2:{},s2's length:{}",s2,s2.len());
let mut s3 = String::new();
s3.push_str("hello rust.");
println!("s3:{}",s3);
s3.push('o');
s3.push('k');
println!("s3:{}",s3);
let s4 = String::from("hello rust and hello world.");
println!("orig.s4:{}",s4);
let result = s4.replace("hello rust and hello world.", "hello world and hello Rust.");
println!("new s4: {}",result);
let s5 = "hello world.".to_string();
println!("s6:{}",s5);
let s7 = String::from("go语言欢喜Ge");
show_name(s7.as_str());
let s8 = " \t tabhello world1.hello world2.hello world3.\r\n ";
println!("s8.len:{}",s8.len());
println!("s8.trim.len:{}",s8.trim().len());
let s9 = " \t tabhello world1.hello world2.hello world3\r\n ";
println!("s8.len:{}",s9.len());
for item in s9.trim().split('.'){
println!("充电科目:{}",item);
}
let s10 = "hahafaksjdfkajfkajskjfd9eqak";
for i in s10.chars(){
println!("char: {} ",i);
}
let s11 = "this is a string, ".to_string();
let s12 = "the second string.".to_string();
let s13 = s11 + &s12;
println!("String s11 + String s12 = String s13: {}",s13);
let code = "80010";
let choose = match code {
"10010" => "china unicom",
"10086" => "china mobile",
"10000" => "china telecom",
_ => "Unknown"
};
println!("choose is: {}",choose);
for num in 1..5{
println!("num: {}", num);
}
for num in 1..=5{
println!("num: {}", num);
}
let studyList = vec![
"Rust Basic",
"Rust Developer",
"Rust Daniu",
];
for name in studyList.iter() {
match name {
&"Rust Daniu" => println!("YYDS!!! {}",name),
_ => println!("Next: {}", name),
}
}
let studyList2 = vec![
"Rust Basic",
"Rust Developer",
"Rust Daniu",
];
println!("studyList2: {:?}",studyList2);
for name in studyList2.into_iter() {
match name {
"Rust Daniu" => println!("YYDS!!! {}",name),
_ => println!("Next: {}", name),
}
}
let mut studyList3 = vec![
"Rust Basic",
"Rust Developer",
"Rust Daniu",
];
println!("studyList3: {:?}",studyList3);
for name in studyList3.iter_mut(){
*name = match name {
&mut "Rust Daniu" => {"wonderful! Daniu"},
_ => *name,
}
}
println!("studyList3: {:?}",studyList3);
let mut num = 1;
while num < 20 {
println!("number is: {}", num);
num = num * 2;
}
println!("### ---------------------------- ###");
let mut num = 1;
loop {
if num > 20 {
break;
};
println!("number is: {}", num);
num = num * 3;
}
}
fn show_name(name:&str){
println!("充电科目:{}",name);
}