New We are sorting MAX channels into categories and territories. Read the news
Loading image…

Вернёмся к строкам. Рассмотрим теперь как сравнивать строки.


В программе ниже всё понятно. Так что, что не буду отдельно её комментировать.

use std::cmp::Ordering;

fn main() {
// сравнение на равенство
let s1 = "Привет".to_string();
let s2 = "привет".to_string();
if s1 == s2 {
println!("равны");
} else {
println!("не равны");
}
// лексиграфическое сравнение
let s11 = "Привет".to_string();
let s22 = "Привет".to_string();
match s11.cmp(&s22) {
Ordering::Less => println!("s11 < s22"),
Ordering::Equal => println!("s11 == s22"),
Ordering::Greater => println!("s11 > s22"),
}
// сравнение с константой (шаблоном)
let s = "Здравствуйте".to_string();
match s.as_str() {
"Здравствуйте" => println!("Привет"),
"До свидания" => println!("Увидимся"),
_ => println!("????"),
}
}
Views: 78
Open in MAX Report an inaccuracy

Report an inaccuracy

Describe what needs fixing. If you have a source, add a link.

You are leaving datool.ru

The link leads to an external website. datool.ru is not responsible for its content — check the address before entering passwords or payment details.

Redirecting in 10 s

Go