Skip to content
เข้าสู่ระบบ

str Functions

Functions สำหรับ string slices (&str) ใน Rust รวมถึง searching, slicing, และ manipulation

Methods พื้นฐานสำหรับตรวจสอบ strings

fn main() {
let s = "Hello, World!";
// Length
println!("Length: {} bytes", s.len());
println!("Chars: {}", s.chars().count());
// Empty check
println!("Is empty: {}", s.is_empty());
// Contains
println!("Contains 'World': {}", s.contains("World"));
println!("Contains 'Rust': {}", s.contains("Rust"));
// Starts/ends with
println!("Starts with 'Hello': {}", s.starts_with("Hello"));
println!("Ends with '!': {}", s.ends_with("!"));
}

เข้าสู่ระบบเพื่อดูเนื้อหาเต็ม

ยืนยันตัวตนด้วยบัญชี Google เพื่อปลดล็อกบทความทั้งหมด