TLang.String

TLang.String provides string manipulation utilities. Import with use TLang.String. TLang.Str is an identical alias.

    use TLang.String
  

Length and Emptiness

      let n     = String.length("hello")        // 5
      let empty = String.isEmpty("")            // true
      let empty = String.isEmpty("hi")          // false
    

Case Conversion

      let up   = String.toUpperCase("hello")    // "HELLO"
      let down = String.toLowerCase("HELLO")    // "hello"
    

Trimming

      let t  = String.trim("  hello  ")         // "hello"
      let ts = String.trimStart("  hello  ")    // "hello  "
      let te = String.trimEnd("  hello  ")      // "  hello"
    

Index Operations

      let i  = String.indexOf("hello world", "world")      // 6
      let li = String.lastIndexOf("abcabc", "b")           // 4
    

Substrings and Slicing

      let sub  = String.substring("hello world", 6)        // "world"
      let sub2 = String.substring("hello world", 0, 5)     // "hello"
      let sl   = String.slice("hello", 1, 4)               // "ell"
    

Split and Join

      let parts = String.split("a,b,c", ",")    // ["a", "b", "c"]
      let lines = String.lines("a\nb\nc")        // ["a", "b", "c"]
      let words = String.words("hello world")    // ["hello", "world"]
    

Replace

      let r1 = String.replace("hello world", "world", "there")   // "hello there"
      let r2 = String.replaceAll("aabbcc", "b", "x")             // "aaxxcc"
    

Concat and Repeat

      let c  = String.concat("hello", " world")    // "hello world"
      let r  = String.repeat("ab", 3)              // "ababab"
    

Character Operations

      let ch   = String.charAt("hello", 1)           // "e"
      let code = String.charCodeAt("A", 0)           // 65
      let str  = String.fromCharCode(65)             // "A"