string_camel_case()

def string_camel_case(s) -> string

Convert a string to camelCase.

Converts a string to camelCase with the first word lowercase and subsequent words capitalized. Handles multiple word separators.

Args

  • s: string: The string to convert

Returns

str: The camelCase string

string_contains()

def string_contains(s, needle, ignore_case) -> bool

Check if a string contains a substring.

Returns True if the string contains the needle substring, optionally with case-insensitive matching.

Args

  • s: string: The string to search in
  • needle: string: The substring to search for
  • ignore_case: bool: If True, performs case-insensitive search. Default is False.

Returns

bool: True if the substring is found, False otherwise

string_ends_with()

def string_ends_with(s, suffix) -> bool

Check if a string ends with a given suffix.

Returns True if the string ends with the specified suffix, False otherwise. This is a case-sensitive check.

Args

  • s: string: The string to check
  • suffix: string: The suffix to look for

Returns

bool: True if the string ends with the suffix, False otherwise

string_format_table()

def string_format_table(rows) -> string

Format a list of dictionaries as an ASCII table.

Converts a list of dictionaries into a formatted ASCII table with column headers and borders. Each dictionary represents a row, with keys as column names and values as cell contents.

Args

  • rows: list: A list of dictionaries, each representing a table row. All rows should have consistent keys (columns).

Returns

str: The formatted ASCII table as a string

string_kebab_case()

def string_kebab_case(s) -> string

Convert a string to kebab-case.

Converts a string to lowercase with words separated by hyphens. Handles camelCase, PascalCase, and space-separated words.

Args

  • s: string: The string to convert

Returns

str: The kebab-case string

string_lower()

def string_lower(s) -> string

Convert a string to lowercase.

Converts all uppercase letters to lowercase. Non-letter characters are unchanged.

Args

  • s: string: The string to convert

Returns

str: The lowercase string

string_pad_left()

def string_pad_left(s, width, fill) -> string

Pad a string on the left to a target width.

Adds characters to the left side of the string to reach the target width. If the string is already at or longer than the target width, returns the original string unchanged.

Args

  • s: string: The string to pad
  • width: int: The target width in characters
  • fill: string: The fill character(s) to use. Default is space. Only the first character is used for single-character fills.

Returns

str: The left-padded string

string_pad_right()

def string_pad_right(s, width, fill) -> string

Pad a string on the right to a target width.

Adds characters to the right side of the string to reach the target width. If the string is already at or longer than the target width, returns the original string unchanged.

Args

  • s: string: The string to pad
  • width: int: The target width in characters
  • fill: string: The fill character(s) to use. Default is space.

Returns

str: The right-padded string

string_regex_captures()

def string_regex_captures(pattern, s)

Extract named capture groups from the first regex match.

Matches the regex pattern and returns a dictionary of named capture groups from the first match. Unnamed groups are ignored.

Raises: Error: If the regex pattern is invalid

Args

  • pattern: string: The regex pattern with named capture groups
  • s: string: The string to search in

Returns

dict or None: Dictionary of named captures if match found, None otherwise

string_regex_find_all()

def string_regex_find_all(pattern, s) -> list

Find all regex matches in a string.

Finds all non-overlapping matches of the regex pattern in the string. Returns a list of match dictionaries, each containing match details.

Each element in the returned list contains:

  • ‘match’: The matched text
  • ‘start’: Starting character (Unicode codepoint) index
  • ’end’: Ending character (Unicode codepoint) index
  • ‘groups’: List of captured groups
  • ’named’: Dictionary of named captures
  • ‘source’: Original source string

Raises: Error: If the regex pattern is invalid

Args

  • pattern: string: The regex pattern to find
  • s: string: The string to search in

Returns

list: List of match dictionaries, empty list if no matches

string_regex_match()

def string_regex_match(pattern, s)

Match a regex pattern against a string.

Searches for the first match of the regex pattern anywhere in the string. Returns a dictionary with match details for the first match found, or None if there is no match.

The returned dictionary contains:

  • ‘match’: The matched text
  • ‘start’: Starting character (Unicode codepoint) index of the match
  • ’end’: Ending character (Unicode codepoint) index of the match
  • ‘groups’: List of captured groups
  • ’named’: Dictionary of named capture groups
  • ‘source’: The original source string

Raises: Error: If the regex pattern is invalid

Args

  • pattern: string: The regex pattern to match
  • s: string: The string to search in

Returns

dict or None: Match information if found, None otherwise

string_replace()

def string_replace(s, from_str, to_str, count, regex, ignore_case) -> string

Replace occurrences of a substring with another string.

Performs string replacement, optionally supporting regex patterns and case-insensitive matching. By default, replaces all occurrences. Use ‘count’ to limit the number of replacements.

Args

  • s: string: The string to perform replacements in
  • from_str: string: The substring (or regex pattern) to replace
  • to_str: string: The replacement string
  • count: int: Maximum number of replacements (-1 for unlimited). Default is -1.
  • regex: bool: If True, treats from_str as a regex pattern. Default is False.
  • ignore_case: bool: If True, performs case-insensitive matching. Default is False.

Returns

str: The string with replacements applied

string_snake_case()

def string_snake_case(s) -> string

Convert a string to snake_case.

Converts a string to lowercase with words separated by underscores. Handles camelCase, PascalCase, and space-separated words.

Args

  • s: string: The string to convert

Returns

str: The snake_case string

string_split_lines()

def string_split_lines(s) -> list

Split a string into lines, handling both Unix and Windows line endings.

Splits the string on newline characters, properly handling both \n (Unix) and \r\n (Windows/DOS) line endings. Always returns a list, even if the input contains no newlines.

Args

  • s: string: The string to split

Returns

list: A list of lines without line ending characters

string_split_whitespace()

def string_split_whitespace(s) -> list

Split a string by whitespace, returning a list of non-empty words.

Splits the string on any whitespace character (space, tab, newline, etc.) and returns only the non-empty parts. Multiple consecutive whitespace characters are treated as a single separator.

Args

  • s: string: The string to split

Returns

list: A list of non-empty words

string_starts_with()

def string_starts_with(s, prefix) -> bool

Check if a string starts with a given prefix.

Returns True if the string begins with the specified prefix, False otherwise. This is a case-sensitive check.

Args

  • s: string: The string to check
  • prefix: string: The prefix to look for

Returns

bool: True if the string starts with the prefix, False otherwise

string_title_case()

def string_title_case(s) -> string

Convert a string to Title Case.

Converts the first letter of each word to uppercase and remaining letters to lowercase. Words are separated by spaces, hyphens, or underscores.

Args

  • s: string: The string to convert

Returns

str: The title-cased string

string_trim()

def string_trim(s) -> string

Remove leading and trailing whitespace from a string.

Strips whitespace characters (spaces, tabs, newlines) from both the beginning and end of the string. The string contents are otherwise unchanged.

Args

  • s: string: The string to trim

Returns

str: The trimmed string

string_trim_end()

def string_trim_end(s) -> string

Remove trailing whitespace from a string.

Strips whitespace characters from the end of the string only. Leading whitespace is preserved.

Args

  • s: string: The string to trim

Returns

str: The string with trailing whitespace removed

string_trim_start()

def string_trim_start(s) -> string

Remove leading whitespace from a string.

Strips whitespace characters from the beginning of the string only. Trailing whitespace is preserved.

Args

  • s: string: The string to trim

Returns

str: The string with leading whitespace removed

string_upper()

def string_upper(s) -> string

Convert a string to uppercase.

Converts all lowercase letters to uppercase. Non-letter characters are unchanged.

Args

  • s: string: The string to convert

Returns

str: The uppercase string