String

The SD.String module provides utility functions for string manipulation in Lua. This document details each function's purpose, parameters, return values, and usage examples.

String.StartsWith

SD.String.StartsWith(str, start)

Purpose: Checks if a string starts with a specified substring.

Parameters:

  • str (string): The string to check.

  • start (string): The substring to match at the start of str.

Returns:

  • (boolean): Returns true if str starts with start, false otherwise.

Usage Example:

print(SD.String.StartsWith("hello world", "hello"))  -- Output: true
print(SD.String.StartsWith("hello world", "world"))  -- Output: false

String.EndsWith

SD.String.EndsWith(str, ending)

Purpose: Checks if a string ends with a specified substring.

Parameters:

  • str (string): The string to check.

  • ending (string): The substring to match at the end of str.

Returns:

  • (boolean): Returns true if str ends with ending, false otherwise.

Usage Example:

print(SD.String.EndsWith("hello world", "world"))  -- Output: true
print(SD.String.EndsWith("hello world", "hello"))  -- Output: false

String.CapitalizeFirst

SD.String.CapitalizeFirst(str)

Purpose: Capitalizes the first letter of a string and converts all other letters to lowercase.

Parameters:

  • str (string): The string to capitalize.

Returns:

  • (string): The string with the first letter capitalized and all subsequent letters in lowercase.

Usage Example:

print(SD.String.CapitalizeFirst("hello world"))  -- Output: "Hello world"

String.Split

SD.String.Split(str, delim)

Purpose: Splits a string into a table of substrings based on a specified delimiter.

Parameters:

  • str (string): The string to split.

  • delim (string): The delimiter to use for splitting the string.

Returns:

  • (table): A table containing the substrings derived from splitting str by delim.

Usage Example:

local result = SD.String.Split("one,two,three", ",")
for i, v in ipairs(result) do
    print(v)  -- Output: "one" "two" "three"
end

Last updated