Here we list the functions provided by the std/strings library for manipulating strings in Tim Engine. These functions allow you to perform common string operations such as concatenation, interpolation, and various utilities for working with strings.
🔗contains
fn contains(s: string, sub: string): boolCheck if the string s contains the substring sub. This function returns true if sub is found within s, and false otherwise.
🔗startsWith
fn startsWith(s: string, prefix: string): boolCheck if the string s starts with the specified prefix. This function returns true if s begins with prefix, and false otherwise.
🔗endsWith
fn endsWith(s: string, suffix: string): boolCheck if the string s ends with the specified suffix. This function returns true if s ends with suffix, and false otherwise.
🔗toUpper
fn toUpper(s: string): stringConvert the string s to uppercase. This function returns a new string with all characters in s converted to uppercase.
🔗toLower
fn toLower(s: string): stringConvert the string s to lowercase. This function returns a new string with all characters in s converted to lowercase.
🔗strip
fn strip(s: string): stringStrip leading and trailing whitespace from the string s.
🔗split
fn split(s: string, sep: string): arraySplit the string s by the separator sep and return an array of substrings.
🔗replace
fn replace(s: string, from: string, to: string): stringReplace all occurrences of from with to in the string s.
🔗repeat
fn repeat(s: string, n: int): stringReturn a new string consisting of n repetitions of the string s.
🔗capitalize
fn capitalize(s: string): stringReturn a copy of the string s with its first character converted to uppercase.
🔗count
fn count(s: string, sub: string): intCount the number of non-overlapping occurrences of sub in the string s.
🔗isAlphaNumeric
fn isAlphaNumeric(s: string): boolCheck if all characters in the string s are alphanumeric.
🔗isDigit
fn isDigit(s: string): boolCheck if all characters in the string s are digits.
🔗Base64 Encoding and Decoding
The std/strings library also provides functions for encoding and decoding strings in Base64 format, which can be useful for encoding binary data or transmitting data in a text-based format.
🔗encode
fn encode(s: string): stringEncode the string s in Base64 format. This function takes a string as input and returns a new string that is the Base64-encoded representation of the input string.
🔗decode
fn decode(s: string): stringDecode a Base64-encoded string s. This function takes a Base64-encoded string as input and returns the original string that was encoded.