|
String handling |
In many languages, strings are expensive — they allocate memory, trigger garbage collection, and often require copying even for simple operations.
Sheerpower takes a different approach. Strings are designed as reusable memory buffers, with support for zero-copy slicing (VIEW), high-speed overlay, and compile-time optimization.
This means you can process millions of strings with predictable performance — without special libraries, workarounds, or manual optimization.
Business applications process massive amounts of text: customer data, logs, transactions, and reports.
Sheerpower is designed for this workload. Strings are handled with high efficiency and predictable performance, even at scale.
Unlike many modern languages, Sheerpower provides memory safety without relying on garbage collection, eliminating pauses and reducing overhead.
The result is a system where string-heavy applications remain fast, stable, and easy to reason about.
Sheerpower's string system is designed around a single principle: avoid unnecessary allocation and copying.
For highly efficient string parsing, Sheerpower offers a
VIEW feature that creates zero-copy views directly
into a source string. Instead of allocating new substrings,
a view stores only positions and references the current buffer
of the source string.
If the source string changes, the VIEW reflects
that change on the next reference. Because views are recalculated only
when used, and cached, repeated access is very fast —
even when parsing large text records or scanning thousands
of fields.
For a detailed guide to string views, see String Views (Zero-Copy Slices).
JOIN() function when you need to
concatenate a large number of strings efficiently.In Sheerpower, three special assignment statements let you modify an existing string without creating a new string. These statements overlay new text directly into the target variable's current buffer:
These operations never expand or shrink the target string. Instead:
This makes LSET, CSET, and RSET useful for fixed-length fields, updating views without reallocation, and producing structured text layouts while avoiding unnecessary memory allocations.
When the source string is longer than the destination, the extra characters are simply discarded:
Normal assignment creates a new string and changes the length of the variable:
Special assignment reuses the existing buffer and keeps the original length:
A %text block turns several source lines into ONE string
literal, exactly as typed — no quoting, no concatenation, no
escape characters:
Everything between %text and %end text is
kept verbatim: leading spaces, blank lines, and
comment indicators such as // and ! are all
part of the string. Lines are joined with CR+LF, with no line ending
after the last line. The markers are case-regardless,
%end text may be indented, and %text must be
the last thing on its line.
The block is an ordinary string literal, so it works anywhere a quoted
string does — assignments, print, function
arguments. It is ideal for blocks of HTML, SQL, test data, or help
text. A single literal can hold up to 16K of text; build larger
strings by concatenating blocks.
Inside an if or a routine, a flush-left block breaks the
visual shape of your code. Add the trim option and the
indentation the lines SHARE is removed from the string, while the
lines' indentation relative to each other is kept:
Note:
Blank lines come out empty, and they are ignored when the margin is
worked out. The margin comes from the least-indented non-blank line:
trim removes only the leading whitespace that all of
those lines share. So if you add one line at a shallower indent, that
line sets a new and smaller margin, and every other line comes out
with the extra spaces still attached. If a block's output suddenly
grows leading spaces, look for the one line whose indentation does
not match the others.
Everything above works on a whole array of strings at once.
Every string function maps over a string array element by element
(ucase$(names$), len(names$),
trim$(padded$)), + concatenates element by
element, and the six comparisons (=, <>,
<, <=, >,
>=) give a mask of ones and zeros with the same rules as
the scalar operators — same(names$, "bob") is the
case-blind mask. The array functions take strings too:
split() and join$() go between text and array,
sort(), unique(), isin() and
filter() pick and order them. One line each:
The full story — shapes, broadcasting, the mask idioms, the set operations — is on the array page: Array Math Functions, Index Lists & Slices, Solve(), Sort(), and More, sections 5, 10, 20, 22 and 24.
(Show/Hide Sheerpower String Handling Takeaways)+ or use
join() for large-scale concatenations.+ and the comparisons act element by
element (a comparison gives a mask), and split()/join$(), sort(),
unique(), isin() and filter() take strings.getword$() use SIDs with a
hinting system for efficient sequential access.fileinfo$() can load entire files directly
into a string variable.%text ... %end text blocks are multi-line string
literals, kept exactly as typed — including indentation
and comment indicators — joined with CR+LF.%text trim removes the indentation the lines
share, so the block can be indented to match the surrounding
code. The least-indented line sets the margin for the whole
block.|
Hide Description
|
|
|
Enter or modify the code below, and then click on RUN |
|
Looking for the full power of Sheerpower?
Check out the Sheerpower website. Free to download. Free to use. |