Strings class is a collection of static APIs for manipulating string.
All methods are static and null-safe. Inspired by Java's String utilities, Go's strings package, and Python's str methods.
- public static string capitalize (string? s)
Capitalize the first character of the string.
- public static string center (string? s, int width, char pad)
Center the string within the specified width using the pad character.
- public static int compareIgnoreCase (string? a, string? b)
Compare two strings lexicographically, ignoring case.
- public static int compareTo (string? a, string? b)
Compare two strings lexicographically.
- public static bool contains (string? s, string? substr)
Returns whether substr is included in the string.
- public static int count (string? s, string? substr)
Count the number of non-overlapping occurrences of substr in s.
- public static bool endsWith (string? s, string? suffix)
Returns whether the string ends with the specified suffix.
- public static bool equalsIgnoreCase (string? a, string? b)
Returns whether two strings are equal, ignoring case.
- public static int indexOf (string? s, string? substr)
Returns the index of the first occurrence of substr in s. Returns -1
if not found.
- public static bool isAlpha (string? s)
Returns whether the string contains only alphabetic characters (a-z, A
-Z).
- public static bool isAlphaNumeric (string? s)
Returns whether the string contains only alphanumeric characters.
- public static bool isBlank (string? s)
Returns whether the string contains only whitespace characters or is
null/empty.
- public static bool isNullOrEmpty (string? str)
Check whether string is null or empty.
- public static bool isNumeric (string? s)
Returns whether the string contains only digit characters (0-9).
- public static string join (string separator, string[] parts)
Join an array of strings with the specified separator.
- public static int lastIndexOf (string? s, string? substr)
Returns the index of the last occurrence of substr in s. Returns -1 if
not found.
- public static string[] lines (string? s)
Split the string by newlines and return as an array.
- public static string padLeft (string? s, int len, char pad)
Pad the string on the left side to the specified length.
- public static string padRight (string? s, int len, char pad)
Pad the string on the right side to the specified length.
- public static string repeat (string? s, int count)
Repeat the string the specified number of times.
- public static string replace (string? s, string old_str, string new_str)
Replace all occurrences of old_str with new_str.
- public static string reverse (string? s)
Reverse the string.
- public static string[] split (string? s, string delimiter)
Split the string by the specified delimiter.
- public static string[] splitByNum (string str, uint num)
Split the string by the specified number of characters and returns it
as an array of strings.
- public static bool startsWith (string? s, string? prefix)
Returns whether the string starts with the specified prefix.
- public static string substring (string? s, int start, int end)
Returns the substring from start (inclusive) to end (exclusive).
- public static string title (string? s)
Capitalize the first letter of each word.
- public static string toCamelCase (string? s)
Convert the string to camelCase. Splits on whitespace, hyphens, and
underscores.
- public static string toKebabCase (string? s)
Convert the string to kebab-case.
- public static string toLowerCase (string? s)
Convert the string to lower case.
- public static string toPascalCase (string? s)
Convert the string to PascalCase.
- public static string toSnakeCase (string? s)
Convert the string to snake_case. Splits on whitespace, hyphens, and
camelCase boundaries.
- public static string toUpperCase (string? s)
Convert the string to upper case.
- public static string trimLeft (string? s, string cutset)
Remove the specified characters from the left side of the string.
- public static string trimPrefix (string? s, string prefix)
Remove the specified prefix from the string if present.
- public static string trimRight (string? s, string cutset)
Remove the specified characters from the right side of the string.
- public static string trimSpace (string str)
Remove whitespace and tabs at the beginning and end of the string.
- public static string trimSuffix (string? s, string suffix)
Remove the specified suffix from the string if present.
- public static string truncate (string? s, int maxLen, string ellipsis)
Truncate the string to the specified maximum length, appending
ellipsis if truncated.
- public static string[] words (string? s)
Split the string by whitespace and return non-empty tokens. Equivalent
to Go's strings.Fields.
- public static string wrap (string? s, int width)
Wrap the string at the specified width by inserting newlines.