The Strings module provides the StringUtils and StringBuilder classes for extensive string manipulation, searching, and efficient concatenation.
To use it: include std/strings.gw.
A utility class providing static methods for string operations. Note: Strings in GW are immutable. These functions return new string instances.
Converts all characters in the string to lowercase.
Converts all characters in the string to uppercase.
Extracts a portion of a string.
- start: The starting index (inclusive).
- end: The ending index (exclusive).
- Returns: The extracted substring.
Checks if the string contains the specified substring.
- Returns:
trueif found,falseotherwise.
Finds the first occurrence of a substring within the string.
- Returns: The starting index of the substring, or
-1if not found.
Removes leading and trailing space characters (" ") from the string.
A mutable class designed for efficient string building and concatenation, avoiding the performance overhead of creating many intermediate immutable string objects.
Initializes an empty string builder.
Initializes the builder with the given starting string.
Appends the given string to the current content.
Appends the given string followed by a newline character (\n).
Overwrites the current content with the new string.
Returns the fully constructed string.
Returns the current number of characters in the builder.
Empties the builder's content.
Converts the internal content to lowercase in-place.
Converts the internal content to uppercase in-place.
# String Utilities
var text = " Hello GW World ";
println("Trimmed: '" + StringUtils.trim(text) + "'");
println("Index of 'GW': " + StringUtils.indexOf(text, "GW"));
println("Contains 'World': " + StringUtils.contains(text, "World"));
println("Substring: " + StringUtils.substring(text, 2, 7)); # "Hello"
# String Building
var sb = StringBuilder("SELECT * FROM users");
sb.append(" WHERE age > 18");
sb.appendLine(";");
sb.toUpper();
println("Query:\n" + sb.toString());