strings
The strings module provides advanced string manipulation beyond built-in methods.
Import
Section titled “Import”import stringsimport { trim, split, join } from stringsBasic Operations
Section titled “Basic Operations”Remove whitespace from both ends:
@strings#trim(" hello ") @// "hello"trim_start
Section titled “trim_start”Remove whitespace from start:
@strings#trim_start(" hello ") @// "hello "trim_end
Section titled “trim_end”Remove whitespace from end:
@strings#trim_end(" hello ") @// " hello"trim_chars
Section titled “trim_chars”Remove specific characters:
@strings#trim_chars("...hello...", ".") @// "hello"Splitting and Joining
Section titled “Splitting and Joining”Split by delimiter:
@strings#split("a,b,c", ",") @// ["a", "b", "c"]split_n
Section titled “split_n”Split into at most n parts:
@strings#split_n("a,b,c,d", ",", 2) @// ["a", "b,c,d"]split_lines
Section titled “split_lines”Split by line breaks:
@strings#split_lines("line1\nline2\nline3")split_whitespace
Section titled “split_whitespace”Split by any whitespace:
@strings#split_whitespace("a b c") @// ["a", "b", "c"]Join strings with delimiter:
@strings#join(["a", "b", "c"], ",") @// "a,b,c"concat
Section titled “concat”Concatenate strings:
@strings#concat("hello", " ", "world") @// "hello world"Case Conversion
Section titled “Case Conversion”to_upper
Section titled “to_upper”Convert to uppercase:
@strings#to_upper("hello") @// "HELLO"to_lower
Section titled “to_lower”Convert to lowercase:
@strings#to_lower("HELLO") @// "hello"to_title
Section titled “to_title”Convert to title case:
@strings#to_title("hello world") @// "Hello World"to_camel
Section titled “to_camel”Convert to camelCase:
@strings#to_camel("hello world") @// "helloWorld"to_pascal
Section titled “to_pascal”Convert to PascalCase:
@strings#to_pascal("hello world") @// "HelloWorld"to_snake
Section titled “to_snake”Convert to snake_case:
@strings#to_snake("helloWorld") @// "hello_world"to_kebab
Section titled “to_kebab”Convert to kebab-case:
@strings#to_kebab("helloWorld") @// "hello-world"Searching
Section titled “Searching”contains
Section titled “contains”Check if string contains substring:
@strings#contains("hello world", "world") @// truestarts_with
Section titled “starts_with”Check prefix:
@strings#starts_with("hello world", "hello") @// trueends_with
Section titled “ends_with”Check suffix:
@strings#ends_with("hello world", "world") @// trueFind first occurrence:
@strings#find("hello world", "world") @// 6find_last
Section titled “find_last”Find last occurrence:
@strings#find_last("hello hello", "hello") @// 6Count occurrences:
@strings#count("hello hello", "hello") @// 2Replacing
Section titled “Replacing”replace
Section titled “replace”Replace all occurrences:
@strings#replace("hello world", "world", "draft") @// "hello draft"replace_n
Section titled “replace_n”Replace first n occurrences:
@strings#replace_n("hello hello", "hello", "hi", 1) @// "hi hello"replace_range
Section titled “replace_range”Replace range:
@strings#replace_range("hello world", 6, 11, "draft") @// "hello draft"Padding
Section titled “Padding”pad_start
Section titled “pad_start”Pad at start to reach length:
@strings#pad_start("hello", 10) @// " hello"@strings#pad_start("hello", 10, "0") @// "00000hello"pad_end
Section titled “pad_end”Pad at end to reach length:
@strings#pad_end("hello", 10) @// "hello "@strings#pad_end("hello", 10, "0") @// "hello00000"Substrings
Section titled “Substrings”substring
Section titled “substring”Extract substring:
@strings#substring("hello world", 0, 5) @// "hello"Slice with range:
@strings#slice("hello world", 6) @// "world"@strings#slice("hello world", 0, 5) @// "hello"Get leftmost characters:
@strings#left("hello", 3) @// "hel"Get rightmost characters:
@strings#right("hello", 3) @// "llo"Reversing
Section titled “Reversing”reverse
Section titled “reverse”Reverse string:
@strings#reverse("hello") @// "olleh"reverse_words
Section titled “reverse_words”Reverse word order:
@strings#reverse_words("hello world") @// "world hello"Characters
Section titled “Characters”Get character array:
@strings#chars("hello") @// ['h', 'e', 'l', 'l', 'o']length
Section titled “length”Get string length:
@strings#length("hello") @// 5is_empty
Section titled “is_empty”Check if empty:
@strings#is_empty("") @// trueValidation
Section titled “Validation”is_alpha
Section titled “is_alpha”Check if all alphabetic:
@strings#is_alpha("hello") @// trueis_numeric
Section titled “is_numeric”Check if all numeric:
@strings#is_numeric("12345") @// trueis_alphanumeric
Section titled “is_alphanumeric”Check if alphanumeric:
@strings#is_alphanumeric("abc123") @// trueis_whitespace
Section titled “is_whitespace”Check if all whitespace:
@strings#is_whitespace(" ") @// trueis_email
Section titled “is_email”Validate email format:
@strings#is_email("user@example.com") @// trueis_url
Section titled “is_url”Validate URL format:
@strings#is_url("https://example.com") @// trueis_ipv4
Section titled “is_ipv4”Validate IPv4 address:
@strings#is_ipv4("192.168.1.1") @// trueEncoding
Section titled “Encoding”base64_encode
Section titled “base64_encode”Encode to Base64:
@strings#base64_encode("hello") @// "aGVsbG8="base64_decode
Section titled “base64_decode”Decode from Base64:
@strings#base64_decode("aGVsbG8=") @// "hello"url_encode
Section titled “url_encode”URL encode:
@strings#url_encode("hello world") @// "hello%20world"url_decode
Section titled “url_decode”URL decode:
@strings#url_decode("hello%20world") @// "hello world"html_encode
Section titled “html_encode”HTML entity encode:
@strings#html_encode("<div>") @// "<div>"html_decode
Section titled “html_decode”HTML entity decode:
@strings#html_decode("<div>") @// "<div>"Hashing
Section titled “Hashing”MD5 hash:
@strings#md5("hello") @// "5d41402abc4b2a76b9719d911017c592"SHA-1 hash:
@strings#sha1("hello") @// "aaf4c61ddcc5e8a2dabede0f3b482cd9aea9434d"sha256
Section titled “sha256”SHA-256 hash:
@strings#sha256("hello") @// "2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824"Formatting
Section titled “Formatting”format
Section titled “format”Format string with arguments:
@strings#format("Hello, {0}!", "World") @// "Hello, World!"template
Section titled “template”Template with named placeholders:
@strings#template("Hello, {name}!", {name: "World"}) @// "Hello, World!"indent
Section titled “indent”Indent each line:
@strings#indent("hello\nworld", 4) @// " hello\n world"dedent
Section titled “dedent”Remove common indentation:
@strings#dedent(" hello\n world") @// "hello\nworld"Wrap text at width:
@strings#wrap("hello world this is a test", 10)@// "hello\nworld this\nis a test"truncate
Section titled “truncate”Truncate with ellipsis:
@strings#truncate("hello world", 8) @// "hello..."Patterns
Section titled “Patterns”wildcard_match
Section titled “wildcard_match”Match with wildcards:
@strings#wildcard_match("hello.txt", "*.txt") @// trueregex_match
Section titled “regex_match”Regular expression match:
@strings#regex_match("hello123", r"\w+\d+") @// trueregex_replace
Section titled “regex_replace”Replace with regex:
@strings#regex_replace("hello123", r"\d+", "") @// "hello"regex_find_all
Section titled “regex_find_all”Find all regex matches:
@strings#regex_find_all("a1b2c3", r"\d") @// ["1", "2", "3"]