Skip to content

std:string

The std:string module provides string manipulation utilities. String arguments (like delimiters, substrings) that can contain escape sequences (e.g., \\n, \\e) will have these processed by the C++ native code. The main string being operated on (e.g., for toNumber, trim) also has its escapes processed if it’s a Nyx string literal.

std-string.nyx
import "std:string" as str_utils;

Converts text_string (escapes processed) to a number.

  • Returns: number or nyx_null on failure.
  • Example: auto n = str_utils.toNumber(" -12.5\\n"); // n is -12.5

Removes leading/trailing whitespace from text_string (escapes processed).

  • Returns: New string.
  • Example: output(str_utils.trim(" hi ")); // "hi"

Converts text_string (escapes processed) to lowercase.

  • Returns: New string.
  • Example: output(str_utils.toLowerCase("NyX")); // "nyx"

Converts text_string (escapes processed) to uppercase.

  • Returns: New string.
  • Example: output(str_utils.toUpperCase("NyX")); // "NYX"

str_utils.contains(main_string, substring)

Section titled “str_utils.contains(main_string, substring)”

Checks if main_string contains substring. Both strings have escapes processed.

  • Returns: true or false.
  • Example: output(str_utils.contains("hello\\nworld", "\\nwo")); // true

str_utils.startsWith(main_string, prefix_string)

Section titled “str_utils.startsWith(main_string, prefix_string)”

Checks if main_string starts with prefix_string. Both strings have escapes processed.

  • Returns: true or false.
  • Example: output(str_utils.startsWith("image.png", "image")); // true

str_utils.endsWith(main_string, suffix_string)

Section titled “str_utils.endsWith(main_string, suffix_string)”

Checks if main_string ends with suffix_string. Both strings have escapes processed.

  • Returns: true or false.
  • Example: output(str_utils.endsWith("image.png", ".png")); // true

str_utils.split(text_string, delimiter_string)

Section titled “str_utils.split(text_string, delimiter_string)”

Splits text_string by delimiter_string. delimiter_string has escapes processed. If processed delimiter is empty, splits into characters. text_string is split as-is (its internal control characters are used).

  • Returns: list of strings.
  • Example: auto parts = str_utils.split("a-b-c", "-"); // ["a","b","c"] auto content = "line1" + NEWLINE + "line2"; auto lines = str_utils.split(content, "\\n"); // ["line1", "line2"]

str_utils.substring(text_string, start_index_num, [length_num])

Section titled “str_utils.substring(text_string, start_index_num, [length_num])”

Extracts substring from text_string. text_string itself is used as-is (its actual characters, not re-processing Nyx literal escapes).

  • Parameters: start_index_num (number), length_num (optional number). Negative indices count from end.
  • Returns: New string.
  • Example: output(str_utils.substring("hello", 1, 3)); // "ell"

str_utils.replace(original_string, old_substring, new_substring)

Section titled “str_utils.replace(original_string, old_substring, new_substring)”

Replaces all occurrences of old_substring with new_substring in original_string. All three string arguments have their escapes processed before replacement.

  • Returns: New string.
  • Example: output(str_utils.replace("bob@example.com", "bob", "alice")); // "alice@example.com"