Under development — the help is being filled in plugin by plugin.
Plugin reference

str

A fast, comprehensive string toolkit (search, slice, replace, convert).

41 functionsnamespace strsource plugins/str/StrPlugin.c
= vs :=

Two assignment operators. Plain = grows the target's capacity as needed; := is capacity-bounded — it never grows, fills up to the declared capacity, and sets Overflow to 1 on truncation. With = a shorter source replaces the full value (new length = source length); with := the existing tail beyond the source is preserved.

Use = for general assignment; use := for fixed-size fields (e.g. a string member of a packed struct) where the buffer must not reallocate. See Language basics → Assignment for the full table and a worked example.

Written from a line-by-line source review; every example output is from a real run.

Introduction

The str plugin is DominScript's text-handling toolkit: searching, slicing, transforming, comparing, converting to and from numbers, and simple splitting. It is built for speed — the search core uses the C library's memchr and memcmp pair (typically SIMD-accelerated), and the character-set operations use a 256-entry presence table, so running time scales with the length of the input.

Loading the plugin

At the top of your script, load the plugin by a path to its file, relative to the script, without the extension. The examples run from the Examples folder, so the path is of the form ../plugins/...:

plugin "../plugins/print/PrintPlugin";
plugin "../plugins/str/StrPlugin";

After that, call functions as str.Function(arguments). A returned string can be passed straight to printf's %s placeholder.

What to know about every function (the basics)

  • Strings are NUL-terminated byte sequences. The apparent length runs up to the first zero byte, so the str plugin is not suitable for true binary data (which may contain 0 bytes) — use the blob plugin for that.

  • Every operation is byte-oriented and ASCII-minded. Case folding and comparison are defined only for the English alphabet; UTF-8 multi-byte characters (such as accented letters) are treated as separate bytes. Len, CharAt and indices therefore count bytes, not "characters".

  • Indexing is 0-based. Search functions return the byte index of the match, or -1 when there is no match.

  • Functions that return a truth value (Contains, StartsWith, IsInt, and so on) return 0 (false) or 1 (true).

  • Transforming functions always return a NEW string and never modify the original; memory is managed by the runtime.

  • Negative or out-of-range indices are handled gracefully (usually clamped to 0 or to the length) rather than raising an error. Only a wrong argument count or type causes a runtime error.

How to read the signatures

[Square brackets] mark an optional argument; the type after the -> arrow is the return type. For example, str.Find(hay, needle [, start [, occurrence]]) -> int means hay and needle are required, start and occurrence are optional, and the result is an integer.

Running

./domin Examples/my_script.dom # Linux
.\domin.exe Examples\my_script.dom # Windows (PowerShell)

Searching

Finding a substring, character or character set, counting occurrences, and checking prefixes and suffixes.

str.Find

str.Find(hay, needle [, start [, occurrence]]) -> int

Finds the first (or the occurrence-th) appearance of needle in hay, starting at start. Matches are non-overlapping.

Parameters
Parameter Type Description
hay string The text to search in.
needle string The substring to look for.
start int Where to begin searching (default: 0). A negative value is clamped to 0.
occurrence int Which match you want, 1-based (default: 1). Values below 1 are treated as 1.
Return value

The 0-based byte index of the match, or -1 if there is no (further) match.

Example
// first match, then the 2nd and 3rd occurrence
printf("%d\n", str.Find("ababab", "ab"));
printf("%d\n", str.Find("ababab", "ab", 0, 2));
printf("%d\n", str.Find("ababab", "ab", 0, 3));
printf("%d\n", str.Find("hello", "z"));
Output after running
0
2
4
-1
When to use

For general searching. To walk over every match in a string, don't increase occurrence (which recounts from the start each call); instead advance start past the previous match in a loop, so you make a single linear pass.

str.FindLast

str.FindLast(hay, needle [, start]) -> int

Finds the LAST appearance of needle (searching backwards). start is the upper bound on the largest starting index considered.

Parameters
Parameter Type Description
hay string The text to search in.
needle string The substring to look for. An empty needle returns the length of hay.
start int The largest allowed start index (default: end of string). A negative value yields -1.
Return value

The 0-based byte index of the last match, or -1 if none.

Example
// last 'ab', then backwards from index 3
printf("%d\n", str.FindLast("ababab", "ab"));
printf("%d\n", str.FindLast("ababab", "ab", 3));
Output after running
4
2
When to use

For finding a file extension or the last separator (such as the last '/' or '.' in a path).

str.FindChar

str.FindChar(hay, code [, start]) -> int

Finds the first appearance of a single byte (character code) from start. The fastest search, because it uses memchr directly.

Parameters
Parameter Type Description
hay string The text to search in.
code int The byte code to find (0–255; the function takes the low 8 bits).
start int Where to begin searching (default: 0).
Return value

The 0-based index of the byte, or -1 if not found.

Example
// look for 'l' (code 108)
printf("%d\n", str.FindChar("hello", 108));
printf("%d\n", str.FindChar("hello", 108, 3));
Output after running
2
3
When to use

When you look for a single character, this is faster and cleaner than Find with a one-character needle. Give the code from str.FromChar's inverse, or directly (e.g. 32 for space).

str.FindAnyOf

str.FindAnyOf(hay, set [, start]) -> int

Returns the first position where the character of hay IS in the set.

Parameters
Parameter Type Description
hay string The text to inspect.
set string The set of characters to look for (order does not matter).
start int Where to begin (default: 0).
Return value

The index of the first matching character, or -1 if none is in the set.

Example
// position of the first digit
printf("%d\n", str.FindAnyOf("abc123", "0123456789"));
Output after running
3
When to use

For simple tokenizing: find the first delimiter from a set of delimiters (for example space, comma and semicolon at once).

str.FindNotOf

str.FindNotOf(hay, set [, start]) -> int

Returns the first position where the character of hay is NOT in the set.

Parameters
Parameter Type Description
hay string The text to inspect.
set string The set of characters to skip over.
start int Where to begin (default: 0).
Return value

The index of the first character not in the set, or -1 if all are in it.

Example
// first non-space character
printf("%d\n", str.FindNotOf(" x", " "));
Output after running
3
When to use

For skipping leading fill characters (space, tab, zero) before you process the real content.

str.Count

str.Count(hay, needle) -> int

Counts the non-overlapping appearances of needle in hay.

Parameters
Parameter Type Description
hay string The text to count in.
needle string The substring to count. An empty needle yields 0.
Return value

The number of occurrences (integer). Counting is non-overlapping.

Example
printf("%d\n", str.Count("ababab", "ab"));
printf("%d\n", str.Count("aaaa", "aa"));
Output after running
3
2
When to use

For statistics or sanity checks (such as how many fields you will get). Note: Count("aaaa","aa") is 2, not 3, because matches do not overlap.

str.Contains

str.Contains(hay, needle) -> int

Tells whether needle occurs anywhere in hay.

Parameters
Parameter Type Description
hay string The text to inspect.
needle string The substring to look for.
Return value

1 if it contains needle; 0 if not.

Example
printf("%d\n", str.Contains("hello world", "wor"));
Output after running
1
When to use

For conditions where only the fact of containment matters, not the position. If you also need the location, use Find instead.

str.StartsWith

str.StartsWith(hay, prefix) -> int

Tells whether hay begins with prefix.

Parameters
Parameter Type Description
hay string The text to inspect.
prefix string The prefix to test for.
Return value

1 if it starts with prefix; 0 if not (also 0 when prefix is longer than the text).

Example
printf("%d\n", str.StartsWith("hello", "he"));
Output after running
1
When to use

For recognizing protocol or command prefixes (does a line start with "GET "), or filtering flag arguments ("--").

str.EndsWith

str.EndsWith(hay, suffix) -> int

Tells whether hay ends with suffix.

Parameters
Parameter Type Description
hay string The text to inspect.
suffix string The suffix to test for.
Return value

1 if it ends with suffix; 0 if not.

Example
printf("%d\n", str.EndsWith("hello", "lo"));
Output after running
1
When to use

For checking a file extension (".png", ".csv") or examining line-ending markers.

Slicing and transforming

These functions always return a new string; the original text stays unchanged.

str.Sub

str.Sub(s, start [, len]) -> string

Returns a substring of length len from position start. When len is omitted, it runs to the end of the string.

Parameters
Parameter Type Description
s string The source text.
start int Start index. A negative value counts from the end (-2 = from the second-to-last character).
len int Length of the slice (default: to the end). An overrunning length is clamped to the end.
Return value

The new substring. If start is past the end of the string, returns an empty string.

Example
printf("%s\n", str.Sub("hello world", 6));
printf("%s\n", str.Sub("hello world", 0, 5));
printf("%s\n", str.Sub("hello", -2));
Output after running
world
hello
lo
When to use

For cutting out fields when you know the positions. The negative start is handy for grabbing the last few characters.

str.Left

str.Left(s, n) -> string

Returns the first n characters of the string.

Parameters
Parameter Type Description
s string The source text.
n int How many characters you want. Negative -> 0; larger than the length -> the whole string.
Return value

A new string of the first n characters.

Example
printf("%s\n", str.Left("hello", 3));
Output after running
hel
When to use

For truncation or extracting a fixed-width prefix. It never runs past the end, so it is safe even without a length check.

str.Right

str.Right(s, n) -> string

Returns the last n characters of the string.

Parameters
Parameter Type Description
s string The source text.
n int How many characters you want. Negative -> 0; larger than the length -> the whole string.
Return value

A new string of the last n characters.

Example
printf("%s\n", str.Right("hello", 3));
Output after running
llo
When to use

For extracting an extension or the last few digits (such as the last four digits of an identifier).

str.Upper

str.Upper(s) -> string

Converts the text to upper case (ASCII a–z only).

Parameters
Parameter Type Description
s string The source text.
Return value

The upper-cased new string.

Example
printf("%s\n", str.Upper("Hello"));
Output after running
HELLO
When to use

For display or normalization. It has no effect on accented letters (they stay as bytes), so be careful with non-English text.

str.Lower

str.Lower(s) -> string

Converts the text to lower case (ASCII A–Z only).

Parameters
Parameter Type Description
s string The source text.
Return value

The lower-cased new string.

Example
printf("%s\n", str.Lower("Hello"));
Output after running
hello
When to use

For preparing a case-insensitive comparison. A quick approach is to Lower both sides (though EqualsIgnoreCase already does this for you).

str.Reverse

str.Reverse(s) -> string

Reverses the order of the string's bytes.

Parameters
Parameter Type Description
s string The source text.
Return value

The reversed new string.

Example
printf("%s\n", str.Reverse("abc"));
Output after running
cba
When to use

For a simple ASCII palindrome check or byte-order reversal. Byte-level reversal corrupts UTF-8 multi-byte characters, so avoid it there.

str.Trim

str.Trim(s) -> string

Strips leading AND trailing whitespace characters (space, tab, newline) from the string.

Parameters
Parameter Type Description
s string The source text.
Return value

The new string trimmed on both sides.

Example
// the [] only shows the boundary
printf("[%s]\n", str.Trim(" hi "));
Output after running
[hi]
When to use

For cleaning up user input or lines read from a file before you compare them or convert them to numbers.

str.TrimLeft

str.TrimLeft(s) -> string

Strips whitespace only from the START of the string.

Parameters
Parameter Type Description
s string The source text.
Return value

The new string trimmed on the left.

Example
printf("[%s]\n", str.TrimLeft(" hi "));
Output after running
[hi ]
When to use

For removing indentation when you want to keep the trailing spaces.

str.TrimRight

str.TrimRight(s) -> string

Strips whitespace only from the END of the string.

Parameters
Parameter Type Description
s string The source text.
Return value

The new string trimmed on the right.

Example
printf("[%s]\n", str.TrimRight(" hi "));
Output after running
[ hi]
When to use

For removing a newline or trailing spaces from lines read from a file.

str.TrimChars

str.TrimChars(s, set) -> string

Strips the characters of the given set from both ends.

Parameters
Parameter Type Description
s string The source text.
set string The set of characters to strip.
Return value

The new string trimmed of the set's characters on both sides.

Example
printf("[%s]\n", str.TrimChars("xxhixx", "x"));
Output after running
[hi]
When to use

For removing quotes, brackets or other framing characters (for example set = "\"'" or "()").

str.Replace

str.Replace(s, from, to [, maxCount]) -> string

Replaces every (or at most maxCount) occurrence of from with to.

Parameters
Parameter Type Description
s string The source text.
from string The substring to find. An empty from leaves the text unchanged.
to string The replacement text (may be empty — that means deletion).
maxCount int How many replacements at most (default: -1 = all).
Return value

The new, replaced string.

Example
printf("%s\n", str.Replace("a.b.c", ".", "-"));
printf("%s\n", str.Replace("aaaa", "a", "b", 2));
Output after running
a-b-c
bbaa
When to use

For swapping delimiters, simple template filling, or deleting characters (empty to). Use maxCount to replace only the first few occurrences.

str.Repeat

str.Repeat(s, n) -> string

Concatenates the string n times.

Parameters
Parameter Type Description
s string The text to repeat.
n int The number of repetitions. Negative -> 0 (empty result).
Return value

The new string repeated n times. A too-large result raises a runtime error.

Example
printf("%s\n", str.Repeat("ab", 3));
Output after running
ababab
When to use

For quickly building separator lines, indentation or padding (for example str.Repeat("-", 40)).

str.PadLeft

str.PadLeft(s, width [, code]) -> string

Pads the string on the left up to the desired width with the given character.

Parameters
Parameter Type Description
s string The source text.
width int The desired total width. If s is already at least this long, it stays unchanged.
code int The padding character's code (default: 32, i.e. space).
Return value

The new left-padded string (at least width long).

Example
// the code of '0' is 48
printf("%s\n", str.PadLeft("7", 3, 48));
Output after running
007
When to use

For zero-padded number display or right-aligned columns (such as numeric values in a fixed-width table).

str.PadRight

str.PadRight(s, width [, code]) -> string

Pads the string on the right up to the desired width with the given character.

Parameters
Parameter Type Description
s string The source text.
width int The desired total width.
code int The padding character's code (default: 32, space).
Return value

The new right-padded string.

Example
printf("[%s]\n", str.PadRight("7", 3));
Output after running
[7 ]
When to use

For left-aligned, fixed-width columns (such as printing names in a table).

str.Insert

str.Insert(s, pos, ins) -> string

Inserts the ins text at position pos.

Parameters
Parameter Type Description
s string The source text.
pos int The insertion point. Negative -> 0; larger than the length -> the end of the string.
ins string The text to insert.
Return value

The new string with the inserted part.

Example
printf("%s\n", str.Insert("helloworld", 5, " "));
Output after running
hello world
When to use

For inserting a separator or tag at a known position; inserting at the end is a simple way to append.

str.Remove

str.Remove(s, pos [, len]) -> string

Removes len characters starting at pos. When len is omitted, it removes to the end.

Parameters
Parameter Type Description
s string The source text.
pos int The start of the removal. Negative -> 0; past the end -> no change.
len int How many characters to remove (default: to the end). An overrunning length is clamped to the end.
Return value

The new string without the removed part.

Example
printf("%s\n", str.Remove("hello world", 5, 1));
Output after running
helloworld
When to use

For removing a specific character or section when you know the position (such as cutting out a separator found with Find).

Comparison and classification

Equality and ordering tests, length, emptiness check, and character-code lookup.

str.Equals

str.Equals(a, b) -> int

Tests exact (byte-for-byte) equality.

Parameters
Parameter Type Description
a string The first text.
b string The second text.
Return value

1 if the two strings are identical; 0 if not.

Example
printf("%d\n", str.Equals("abc", "abc"));
Output after running
1
When to use

A reliable equality check. Cleaner than comparing Compare's result to zero.

str.EqualsIgnoreCase

str.EqualsIgnoreCase(a, b) -> int

Tests case-insensitive equality (ASCII).

Parameters
Parameter Type Description
a string The first text.
b string The second text.
Return value

1 if they are equal ignoring case; 0 if not.

Example
printf("%d\n", str.EqualsIgnoreCase("AB", "ab"));
Output after running
1
When to use

For comparing user input or keywords where case does not matter (such as "YES"/"yes").

str.Compare

str.Compare(a, b) -> int

Compares two strings lexicographically (byte by byte).

Parameters
Parameter Type Description
a string The first text.
b string The second text.
Return value

-1 if a is less than b; 0 if equal; 1 if a is greater.

Example
printf("%d\n", str.Compare("abc", "abd"));
printf("%d\n", str.Compare("abc", "abc"));
Output after running
-1
0
When to use

For sorting or three-way decisions. The comparison is byte-based, so upper-case letters sort before lower-case ones (ASCII order).

str.CompareIgnoreCase

str.CompareIgnoreCase(a, b) -> int

Case-insensitive lexicographic comparison (ASCII).

Parameters
Parameter Type Description
a string The first text.
b string The second text.
Return value

-1 / 0 / 1, ignoring case.

Example
printf("%d\n", str.CompareIgnoreCase("ABC", "abc"));
Output after running
0
When to use

For case-independent sorting (such as putting words in alphabetical order regardless of capitalization).

str.Len

str.Len(s) -> int

Returns the length of the string in bytes.

Parameters
Parameter Type Description
s string The text to inspect.
Return value

The number of bytes up to the first NUL byte.

Example
printf("%d\n", str.Len("hello"));
Output after running
5
When to use

For length checks and loop bounds. Remember: this is a byte length, not a "character count" — for accented UTF-8 text the two differ.

str.IsEmpty

str.IsEmpty(s) -> int

Tells whether the string is empty.

Parameters
Parameter Type Description
s string The text to inspect.
Return value

1 if the string is empty; 0 otherwise.

Example
printf("%d\n", str.IsEmpty(""));
printf("%d\n", str.IsEmpty("x"));
Output after running
1
0
When to use

More readable than str.Len(s) == 0. For checking the presence of input or a field.

str.CharAt

str.CharAt(s, index) -> int

Returns the code of the byte at position index.

Parameters
Parameter Type Description
s string The text to inspect.
index int The 0-based byte index.
Return value

The byte code between 0 and 255, or -1 if the index is out of range.

Example
// the code of 'B' is 66
printf("%d\n", str.CharAt("ABC", 1));
printf("%d\n", str.CharAt("ABC", 9));
Output after running
66
-1
When to use

For character-by-character processing. The -1 return also marks the end of range, so it works as a loop end condition. Turn a code back into a character with str.FromChar.

Conversion

Converting between text and numbers in both directions, plus simple validity checks.

str.ToInt

str.ToInt(s) -> int

Reads an integer from the start of the string (base 10). Lenient: it ignores trailing junk after the number.

Parameters
Parameter Type Description
s string The text containing digits.
Return value

The parsed integer; 0 if it does not start with a number.

Example
printf("%d\n", str.ToInt("42"));
printf("%d\n", str.ToInt("12abc"));
Output after running
42
12
When to use

Good when the input certainly starts with a number. If you must tell "invalid" apart from "0", use IsInt or ToIntOr instead.

str.ToIntOr

str.ToIntOr(s, default) -> int

Converts to an integer, but ONLY if the whole string is a clean integer (no leftover). Otherwise it returns the default.

Parameters
Parameter Type Description
s string The text to convert.
default int Returned when the string is not a clean integer.
Return value

The number if the whole string is a valid integer; otherwise the default.

Example
printf("%d\n", str.ToIntOr("42", -1));
printf("%d\n", str.ToIntOr("12abc", -1));
Output after running
42
-1
When to use

The safest choice for user input: it handles the invalid case in a single step with a meaningful default (such as -1 or 0).

str.IsInt

str.IsInt(s) -> int

Checks whether the whole string is a single valid integer (with no leftover).

Parameters
Parameter Type Description
s string The text to inspect.
Return value

1 if it is a clean integer; 0 if not (an empty string is also 0).

Example
printf("%d\n", str.IsInt("42"));
printf("%d\n", str.IsInt("12abc"));
Output after running
1
0
When to use

For validating input before the actual conversion, when you want to handle the invalid case separately.

str.ToFloat

str.ToFloat(s) -> float

Reads a floating-point number from the start of the string. Lenient, like ToInt.

Parameters
Parameter Type Description
s string The text containing a number.
Return value

The parsed floating-point value; 0.0 if it is not a number.

Example
// print the float readably via FromFloat
printf("%s\n", str.FromFloat(str.ToFloat("3.14"), 2));
Output after running
3.14
When to use

For reading measurements, prices or coordinates. The decimal mark is the C-locale dot; for comma decimals, first swap to a dot (str.Replace).

str.FromInt

str.FromInt(n) -> string

Builds a string from an integer (base 10).

Parameters
Parameter Type Description
n int The integer to convert.
Return value

The textual form of the number.

Example
printf("%s\n", str.FromInt(42));
Output after running
42
When to use

For concatenating a number with text, or when you want to format the number further with string operations (PadLeft, etc.).

str.FromFloat

str.FromFloat(x [, decimals]) -> string

Builds a string from a floating-point (or integer) number with a fixed number of decimals.

Parameters
Parameter Type Description
x float The number to convert (an integer is also accepted).
decimals int The number of decimal places (default: 6; clamped to between 0 and 17).
Return value

The textual form of the number with decimals decimal places.

Example
printf("%s\n", str.FromFloat(3.14159));
printf("%s\n", str.FromFloat(3.14159, 2));
Output after running
3.141590
3.14
When to use

For consistent display of money amounts or metrics. Give an explicit decimals value, or you always get 6 decimals.

str.FromChar

str.FromChar(code) -> string

Builds a one-character string from a single byte code.

Parameters
Parameter Type Description
code int The character code (the low 8 bits are taken).
Return value

A string of length one containing that byte.

Example
// the code of 'A' is 65
printf("%s\n", str.FromChar(65));
Output after running
A
When to use

For building text from a character code (the counterpart of CharAt), or producing a special separator (tab = 9).

Splitting

Simple, index-based splitting along a separator — without an array type.

str.SplitCount

str.SplitCount(s, sep) -> int

Counts how many fields the sep separator would split the string into.

Parameters
Parameter Type Description
s string The text to split.
sep string The separator. An empty sep yields 1.
Return value

The number of fields (always at least 1).

Example
printf("%d\n", str.SplitCount("a,b,c", ","));
Output after running
3
When to use

For the upper bound of a SplitGet loop: first SplitCount, then SplitGet from 0 to count-1.

str.SplitGet

str.SplitGet(s, sep, index) -> string

Returns the index-th (0-based) field of the string split along sep.

Parameters
Parameter Type Description
s string The text to split.
sep string The separator.
index int The 0-based number of the requested field.
Return value

The field's text. A negative or too-large index yields an empty string.

Example
printf("%s\n", str.SplitGet("a,b,c", ",", 1));
// index too large -> empty
printf("[%s]\n", str.SplitGet("a,b,c", ",", 9));
Output after running
b
[]
When to use

For processing CSV-like lines or compound keys when you do not need a full array. For many fields, note that each call searches from the start; for heavy processing, Find + Sub in a single pass is faster.

Practical notes

Performance

  • The search functions (Find, Count, Replace, SplitGet) use the fast memchr/memcmp pair internally rather than a naive pairwise scan, so they are fast even on large text.

  • To walk over every match in a string, call Find in a loop while advancing the start parameter (a single pass). The occurrence parameter recounts from the start of the string on every call, so it is slower for many matches.

  • The character-set functions (FindAnyOf, FindNotOf, TrimChars) build a 256-entry table, so their cost scales with the length of the text, regardless of the size of the set.

Common pitfalls

  • Byte vs character: Len, CharAt and indices count bytes. In accented (UTF-8) text a single "letter" can be several bytes, and Upper/Lower/Reverse are correct only for the ASCII range.

  • Binary data: if the text may contain a 0 byte, the str plugin only "sees" up to the first zero — use the blob plugin in that case.

  • ToInt vs ToIntOr: ToInt silently returns 0 for invalid input; if you must distinguish a real 0 from an error, use IsInt or ToIntOr.

  • FromFloat decimals: it gives 6 decimals by default; for display it is almost always worth giving an explicit decimals value.

Error handling

The functions report a wrong argument count or type as a runtime error, and the script stops. Content-level edge cases (a negative or too-large index, no match), however, are handled not as errors but with a graceful return value: searches return -1, and slicing functions return an empty string or a result clamped to the boundary. So in the usual cases you do not need extra guard checks.

The map key-value plugin

Thread-safe associative store — complete function reference