str Functions
Functions สำหรับ string slices (&str) ใน Rust รวมถึง searching, slicing, และ manipulation
1. Basic String Operations
Section titled “1. Basic String Operations”Methods พื้นฐานสำหรับตรวจสอบ strings
Basic Checks
Section titled “Basic Checks”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 เพื่อปลดล็อกบทความทั้งหมด
Login with Google