|
// retoor <retoor@molodetz.nl>
|
|
|
|
System.print("=== String Methods Demo ===\n")
|
|
|
|
System.print("--- Case Conversion ---")
|
|
var text = "Hello World"
|
|
System.print("Original: %(text)")
|
|
System.print("lower: %(text.lower)")
|
|
System.print("upper: %(text.upper)")
|
|
System.print("capitalize: %("hello world".capitalize)")
|
|
System.print("title: %("hello world".title)")
|
|
System.print("swapCase: %(text.swapCase)")
|
|
|
|
System.print("\n--- Character Testing ---")
|
|
System.print("\"hello\".isLower: %("hello".isLower)")
|
|
System.print("\"HELLO\".isUpper: %("HELLO".isUpper)")
|
|
System.print("\"12345\".isDigit: %("12345".isDigit)")
|
|
System.print("\"hello\".isAlpha: %("hello".isAlpha)")
|
|
System.print("\"hello1\".isAlphaNumeric: %("hello1".isAlphaNumeric)")
|
|
System.print("\" \".isSpace: %(" ".isSpace)")
|
|
System.print("\"hello\".isAscii: %("hello".isAscii)")
|
|
|
|
System.print("\n--- Search ---")
|
|
var sentence = "hello world hello"
|
|
System.print("Text: %(sentence)")
|
|
System.print("lastIndexOf(\"hello\"): %(sentence.lastIndexOf("hello"))")
|
|
System.print("lastIndexOf(\"hello\", 11): %(sentence.lastIndexOf("hello", 11))")
|
|
|
|
System.print("\n--- Transformation ---")
|
|
System.print("\"hello\".reverse: %("hello".reverse)")
|
|
System.print("\"hi\".center(10, \"-\"): %("hi".center(10, "-"))")
|
|
System.print("\"42\".lpad(5, \"0\"): %("42".lpad(5, "0"))")
|
|
System.print("\"hi\".rpad(5, \".\"): %("hi".rpad(5, "."))")
|
|
System.print("\"42\".zfill(5): %("42".zfill(5))")
|
|
System.print("\"-42\".zfill(6): %("-42".zfill(6))")
|
|
|
|
System.print("\n--- Prefix/Suffix ---")
|
|
System.print("removePrefix(\"Hello\"): %("HelloWorld".removePrefix("Hello"))")
|
|
System.print("removeSuffix(\"World\"): %("HelloWorld".removeSuffix("World"))")
|
|
|
|
System.print("\n--- Comparison ---")
|
|
System.print("\"apple\" < \"banana\": %("apple" < "banana")")
|
|
System.print("\"banana\" > \"apple\": %("banana" > "apple")")
|
|
System.print("\"abc\" <= \"abc\": %("abc" <= "abc")")
|
|
System.print("\"abc\" >= \"abc\": %("abc" >= "abc")")
|
|
System.print("\"abc\" < \"abcd\": %("abc" < "abcd")")
|
|
System.print("\"abcd\" > \"abc\": %("abcd" > "abc")")
|
|
System.print("\"Z\" < \"a\": %("Z" < "a")")
|
|
|
|
var fruits = ["cherry", "apple", "banana"]
|
|
System.print("Sorted: %(fruits.sort {|a, b| a < b})")
|
|
|
|
System.print("\n--- Splitting ---")
|
|
var lines = "line1\nline2\nline3".splitLines
|
|
System.print("splitLines: %(lines)")
|
|
|
|
var chars = "abc".chars
|
|
System.print("chars: %(chars)")
|
|
|
|
System.print("\n--- Conversion ---")
|
|
System.print("\"42\".toNum: %("42".toNum)")
|
|
System.print("\"3.14\".toNum: %("3.14".toNum)")
|
|
System.print("\"abc\".toNum: %("abc".toNum)")
|