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.
| 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. |
The 0-based byte index of the match, or -1 if there is no (further) match.
// 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"));0 2 4 -1
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.
| 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. |
The 0-based byte index of the last match, or -1 if none.
// last 'ab', then backwards from index 3
printf("%d\n", str.FindLast("ababab", "ab"));
printf("%d\n", str.FindLast("ababab", "ab", 3));4 2
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.
| 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). |
The 0-based index of the byte, or -1 if not found.
// look for 'l' (code 108)
printf("%d\n", str.FindChar("hello", 108));
printf("%d\n", str.FindChar("hello", 108, 3));2 3
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.
| 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). |
The index of the first matching character, or -1 if none is in the set.
// position of the first digit
printf("%d\n", str.FindAnyOf("abc123", "0123456789"));3
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.
| 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). |
The index of the first character not in the set, or -1 if all are in it.
// first non-space character
printf("%d\n", str.FindNotOf(" x", " "));3
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.
| Parameter | Type | Description |
|---|---|---|
| hay | string | The text to count in. |
| needle | string | The substring to count. An empty needle yields 0. |
The number of occurrences (integer). Counting is non-overlapping.
printf("%d\n", str.Count("ababab", "ab"));
printf("%d\n", str.Count("aaaa", "aa"));3 2
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.
| Parameter | Type | Description |
|---|---|---|
| hay | string | The text to inspect. |
| needle | string | The substring to look for. |
1 if it contains needle; 0 if not.
printf("%d\n", str.Contains("hello world", "wor"));1
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.
| Parameter | Type | Description |
|---|---|---|
| hay | string | The text to inspect. |
| prefix | string | The prefix to test for. |
1 if it starts with prefix; 0 if not (also 0 when prefix is longer than the text).
printf("%d\n", str.StartsWith("hello", "he"));1
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.
| Parameter | Type | Description |
|---|---|---|
| hay | string | The text to inspect. |
| suffix | string | The suffix to test for. |
1 if it ends with suffix; 0 if not.
printf("%d\n", str.EndsWith("hello", "lo"));1
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.
| 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. |
The new substring. If start is past the end of the string, returns an empty string.
printf("%s\n", str.Sub("hello world", 6));
printf("%s\n", str.Sub("hello world", 0, 5));
printf("%s\n", str.Sub("hello", -2));world hello lo
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.
| Parameter | Type | Description |
|---|---|---|
| s | string | The source text. |
| n | int | How many characters you want. Negative -> 0; larger than the length -> the whole string. |
A new string of the first n characters.
printf("%s\n", str.Left("hello", 3));hel
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.
| Parameter | Type | Description |
|---|---|---|
| s | string | The source text. |
| n | int | How many characters you want. Negative -> 0; larger than the length -> the whole string. |
A new string of the last n characters.
printf("%s\n", str.Right("hello", 3));llo
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).
| Parameter | Type | Description |
|---|---|---|
| s | string | The source text. |
The upper-cased new string.
printf("%s\n", str.Upper("Hello"));HELLO
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).
| Parameter | Type | Description |
|---|---|---|
| s | string | The source text. |
The lower-cased new string.
printf("%s\n", str.Lower("Hello"));hello
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.
| Parameter | Type | Description |
|---|---|---|
| s | string | The source text. |
The reversed new string.
printf("%s\n", str.Reverse("abc"));cba
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.
| Parameter | Type | Description |
|---|---|---|
| s | string | The source text. |
The new string trimmed on both sides.
// the [] only shows the boundary
printf("[%s]\n", str.Trim(" hi "));[hi]
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.
| Parameter | Type | Description |
|---|---|---|
| s | string | The source text. |
The new string trimmed on the left.
printf("[%s]\n", str.TrimLeft(" hi "));[hi ]
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.
| Parameter | Type | Description |
|---|---|---|
| s | string | The source text. |
The new string trimmed on the right.
printf("[%s]\n", str.TrimRight(" hi "));[ hi]
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.
| Parameter | Type | Description |
|---|---|---|
| s | string | The source text. |
| set | string | The set of characters to strip. |
The new string trimmed of the set's characters on both sides.
printf("[%s]\n", str.TrimChars("xxhixx", "x"));[hi]
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.
| 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). |
The new, replaced string.
printf("%s\n", str.Replace("a.b.c", ".", "-"));
printf("%s\n", str.Replace("aaaa", "a", "b", 2));a-b-c bbaa
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.
| Parameter | Type | Description |
|---|---|---|
| s | string | The text to repeat. |
| n | int | The number of repetitions. Negative -> 0 (empty result). |
The new string repeated n times. A too-large result raises a runtime error.
printf("%s\n", str.Repeat("ab", 3));ababab
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.
| 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). |
The new left-padded string (at least width long).
// the code of '0' is 48
printf("%s\n", str.PadLeft("7", 3, 48));007
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.
| Parameter | Type | Description |
|---|---|---|
| s | string | The source text. |
| width | int | The desired total width. |
| code | int | The padding character's code (default: 32, space). |
The new right-padded string.
printf("[%s]\n", str.PadRight("7", 3));[7 ]
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.
| 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. |
The new string with the inserted part.
printf("%s\n", str.Insert("helloworld", 5, " "));hello world
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.
| 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. |
The new string without the removed part.
printf("%s\n", str.Remove("hello world", 5, 1));helloworld
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.
| Parameter | Type | Description |
|---|---|---|
| a | string | The first text. |
| b | string | The second text. |
1 if the two strings are identical; 0 if not.
printf("%d\n", str.Equals("abc", "abc"));1
A reliable equality check. Cleaner than comparing Compare's result to zero.
str.EqualsIgnoreCase
str.EqualsIgnoreCase(a, b) -> int
Tests case-insensitive equality (ASCII).
| Parameter | Type | Description |
|---|---|---|
| a | string | The first text. |
| b | string | The second text. |
1 if they are equal ignoring case; 0 if not.
printf("%d\n", str.EqualsIgnoreCase("AB", "ab"));1
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).
| Parameter | Type | Description |
|---|---|---|
| a | string | The first text. |
| b | string | The second text. |
-1 if a is less than b; 0 if equal; 1 if a is greater.
printf("%d\n", str.Compare("abc", "abd"));
printf("%d\n", str.Compare("abc", "abc"));-1 0
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).
| Parameter | Type | Description |
|---|---|---|
| a | string | The first text. |
| b | string | The second text. |
-1 / 0 / 1, ignoring case.
printf("%d\n", str.CompareIgnoreCase("ABC", "abc"));0
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.
| Parameter | Type | Description |
|---|---|---|
| s | string | The text to inspect. |
The number of bytes up to the first NUL byte.
printf("%d\n", str.Len("hello"));5
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.
| Parameter | Type | Description |
|---|---|---|
| s | string | The text to inspect. |
1 if the string is empty; 0 otherwise.
printf("%d\n", str.IsEmpty(""));
printf("%d\n", str.IsEmpty("x"));1 0
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.
| Parameter | Type | Description |
|---|---|---|
| s | string | The text to inspect. |
| index | int | The 0-based byte index. |
The byte code between 0 and 255, or -1 if the index is out of range.
// the code of 'B' is 66
printf("%d\n", str.CharAt("ABC", 1));
printf("%d\n", str.CharAt("ABC", 9));66 -1
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.
| Parameter | Type | Description |
|---|---|---|
| s | string | The text containing digits. |
The parsed integer; 0 if it does not start with a number.
printf("%d\n", str.ToInt("42"));
printf("%d\n", str.ToInt("12abc"));42 12
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.
| Parameter | Type | Description |
|---|---|---|
| s | string | The text to convert. |
| default | int | Returned when the string is not a clean integer. |
The number if the whole string is a valid integer; otherwise the default.
printf("%d\n", str.ToIntOr("42", -1));
printf("%d\n", str.ToIntOr("12abc", -1));42 -1
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).
| Parameter | Type | Description |
|---|---|---|
| s | string | The text to inspect. |
1 if it is a clean integer; 0 if not (an empty string is also 0).
printf("%d\n", str.IsInt("42"));
printf("%d\n", str.IsInt("12abc"));1 0
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.
| Parameter | Type | Description |
|---|---|---|
| s | string | The text containing a number. |
The parsed floating-point value; 0.0 if it is not a number.
// print the float readably via FromFloat
printf("%s\n", str.FromFloat(str.ToFloat("3.14"), 2));3.14
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).
| Parameter | Type | Description |
|---|---|---|
| n | int | The integer to convert. |
The textual form of the number.
printf("%s\n", str.FromInt(42));42
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.
| 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). |
The textual form of the number with decimals decimal places.
printf("%s\n", str.FromFloat(3.14159));
printf("%s\n", str.FromFloat(3.14159, 2));3.141590 3.14
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.
| Parameter | Type | Description |
|---|---|---|
| code | int | The character code (the low 8 bits are taken). |
A string of length one containing that byte.
// the code of 'A' is 65
printf("%s\n", str.FromChar(65));A
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.
| Parameter | Type | Description |
|---|---|---|
| s | string | The text to split. |
| sep | string | The separator. An empty sep yields 1. |
The number of fields (always at least 1).
printf("%d\n", str.SplitCount("a,b,c", ","));3
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.
| Parameter | Type | Description |
|---|---|---|
| s | string | The text to split. |
| sep | string | The separator. |
| index | int | The 0-based number of the requested field. |
The field's text. A negative or too-large index yields an empty string.
printf("%s\n", str.SplitGet("a,b,c", ",", 1));
// index too large -> empty
printf("[%s]\n", str.SplitGet("a,b,c", ",", 9));b []
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