priprava retazce

This commit is contained in:
Priec
2026-02-06 18:15:54 +01:00
parent 16ab9dd417
commit bd3036c63c
4 changed files with 33 additions and 1 deletions

View File

@@ -0,0 +1,19 @@
fn main() {
// 1. How to create it
let letter: char = 'a'; // Use SINGLE quotes for char
let emoji: char = '🦀'; // Even emojis are exactly ONE char
// 2. Why it's useful
// You can ask it questions:
println!("{}", letter.is_alphabetic()); // Prints: true
println!("{}", letter.is_numeric()); // Prints: false
// 3. Converting to a number (The "Address" of the letter)
// Every letter has a unique number in the world (Unicode).
let number = 'a' as u32;
println!("{}", number); // Prints: 65
// 4. Converting a number back to a letter
let back_to_char = std::char::from_u32(97);
println!("{:?}", back_to_char); // Prints: Some('A')
}