Sheerpower Logo

String handling


Business applications often work with massive amounts of text. Sheerpower handles strings differently than most languages to ensure maximum efficiency. Unlike many modern languages, Sheerpower provides memory safety without garbage collection.

Performance and Memory Architecture

Sheerpower String Handling Overview

Sheerpower handles strings differently than most languages to ensure maximum efficiency.

  • Mutability & Buffer Reuse

    Strings in Sheerpower are mutable. If a variable holds "The rain in Spain" and is updated to "Enjoy life", Sheerpower repurposes the existing memory buffer rather than creating a new object.
  • No Garbage Collection

    Sheerpower manages memory through dynamic memory pools. You do not need to worry about memory leaks, allocations, or deallocations. And because there is no garbage collector, your application avoids the random slowdowns and pauses common in other languages.
  • Smart Copying (SIDs)

    Every string has a globally unique String ID (SID). When copying strings, Sheerpower checks the SID first. If the source and target SIDs already match, it skips the copy process entirely to increase performance.
  • Efficiency Example: SIDs used as a Hinting System

    Sheerpower uses an internal String ID (SID) based hinting system.
    • You read the Bible into bible$.
    • You call getword$(bible$, 1000). The system records this position.
    • A subsequent call to getword$(bible$, 1001) resumes directly from that SID-enabled hint, rather than re-scanning the first 1000 words.
    • Zero-Copy String Views

      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 offsets 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 lazily recalculated 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 the String Views tutorial.


Sheerpower provides memory safety without garbage collection. This eliminates the string handling slowdowns that other languages experience

Note: See the fileinfo$() function for an easy way to read the entire contents of a file, such as the Bible, into a variable.

Basic Operations: Concatenation

To concatenate (combine) two or more strings, use the plus sign (+). For example, string1 + string2 will join them. Additionally, you can use the JOIN() function when you need to concatenate a large number of strings efficiently.
fullname$ = 'Sally Sue' sentence$ = fullname$ + ' was here.' print sentence$ sentence$ = 'So I heard.' print sentence$ sentence$ = '' l = join(sentence$, fullname$, ' was here') print sentence$

Special Assignment Statements: LSET, CSET, RSET

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:

  • LSET — left-justify and space-fill
  • CSET — center within the target
  • RSET — right-justify and space-fill

These operations never expand or shrink the target string. Instead:

  • If the new string is longer than the target, it is truncated.
  • If the new string is shorter, it is positioned (left, centered, or right) and the remainder is space-filled.

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.

Syntax

LSET target$ = source$ CSET target$ = source$ RSET target$ = source$

LSET / CSET / RSET Visual

Base
x$ = "12345"
1
2
3
4
5
Original 5-character field.
LSET
LSET x$ = "abc"
a
b
c
 
 
Left-justified, space-filled on the right: "abc··".
CSET
CSET x$ = "abc"
 
a
b
c
 
Centered with one space on each side: "·abc·".
RSET
RSET x$ = "abc"
 
 
a
b
c
Right-justified, space-filled on the left: "··abc".
Original field New text Space padding

Examples

x$ = "12345" // Left-justify and pad with spaces LSET x$ = "abc" // x$ is now: "abc " // Center within the field CSET x$ = "abc" // x$ is now: " abc " // Right-justify and pad with spaces RSET x$ = "abc" // x$ is now: " abc"

When the source string is longer than the destination, the extra characters are simply discarded:

x$ = "12345" LSET x$ = "TOO-LONG" // x$ becomes: "TOO-L"

Behavior Summary

Key Points:
  • LSET, CSET, and RSET never allocate new memory for the target string.
  • They overlay directly into the existing string buffer, preserving the original length.
  • Longer source strings are truncated to fit the target length.
  • Shorter source strings are space-padded and positioned left, centered, or right.
  • These operations work naturally and efficiently on VIEW variables.

Comparison to Normal Assignment

Normal assignment creates a new string and changes the length of the variable:

x$ = "12345" x$ = "abc" // x$ becomes "abc"

Special assignment reuses the existing buffer and keeps the original length:

x$ = "12345" LSET x$ = "abc" // x$ becomes "abc "
(Show/Hide Sheerpower String Handling Takeaways)
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.