PBXB64 String Operations
30+ Functions
Standard
Full ANSI and WSTRING support with 30+ built-in string functions. WSTRING intrinsics (WLEN, WLEFT$, WRIGHT$, WMID$), MID$ assignment, INSTR, UCASE$, LCASE$, TRIM$, LSET, RSET, and more. BYREF string parameters are fully supported with correct lifetime management.
ANSI String Functions
ANSI string operations
FUNCTION PBMAIN() AS LONG
LOCAL s AS STRING
LOCAL t AS STRING
s = " Hello World "
PRINT "LEN: "; LEN(s) ' 15
PRINT "TRIM$: "; TRIM$(s) ' "Hello World"
PRINT "LCASE$: "; LCASE$(s) ' " hello world "
PRINT "UCASE$: "; UCASE$(s) ' " HELLO WORLD "
t = LEFT$(s, 7) ' " Hello"
t = RIGHT$(s, 6) ' "orld "
t = MID$(s, 5, 3) ' "lo "
PRINT "INSTR: "; INSTR(s, "World") ' 9
' Assignment via MID$
MID$(s, 9, 5) = "Universe"
PRINT "After: "; s ' " Hello Universe"
FUNCTION = 0
END FUNCTION
Full ANSI string API: LEN, LEFT$, RIGHT$, MID$, INSTR, UCASE$, LCASE$, TRIM$, LTRIM$, RTRIM$, SPACE$, STRING$, CHOOSE$, FORMAT$, STR$, VAL, HEX$, OCT$, BIN$.
WSTRING - Wide Character Strings
Full Unicode support with WSTRING intrinsics. UTF-16 encoding, correct length counting, and BYREF passing.
WSTRING Unicode operations
FUNCTION PBMAIN() AS LONG
LOCAL ws AS WSTRING
ws = "Hello World"
PRINT "WLEN: "; WLEN(ws) ' 11
PRINT "WLEFT$: "; WLEFT$(ws, 5) ' "Hello"
PRINT "WRIGHT$: "; WRIGHT$(ws, 5) ' "World"
PRINT "WMID$: "; WMID$(ws, 7, 3) ' "Wor"
' Unicode content
ws = "Grüße"
PRINT "WLEN: "; WLEN(ws) ' 5 (characters, not bytes)
FUNCTION = 0
END FUNCTION
WSTRING intrinsics: WLEN, WLEFT$, WRIGHT$, WMID$, WINSTR, WUCASE$, WLCASE$, WTRIM$. Correct character counting (not byte counting) for UTF-16 content.
LSET / RSET - Fixed-Width Padding
Left/right padding
FUNCTION PBMAIN() AS LONG
LOCAL s AS STRING
s = SPACE$(20)
LSET s = "Hello" ' Left-aligned, padded right
PRINT "LSET: |"; s; "|"
s = SPACE$(20)
RSET s = "Hello" ' Right-aligned, padded left
PRINT "RSET: |"; s; "|"
FUNCTION = 0
END FUNCTION
LSET and RSET are real implementations (not stubs), producing left-aligned and right-aligned fixed-width strings. Also: CSET/CSET$ for centering.
BYREF String Parameters
Strings passed BYREF are correctly handled with caller-owned lifetime and GEP-based addressing.
BYREF string modification
FUNCTION ModifyString(BYREF s AS STRING) AS LONG
s = "Modified"
FUNCTION = 0
END FUNCTION
FUNCTION PBMAIN() AS LONG
LOCAL msg AS STRING
msg = "Original"
ModifyString(msg)
PRINT msg ' "Modified"
FUNCTION = 0
END FUNCTION
BYREF string parameters pass the address (not the value), allowing the callee to modify the caller's string. String cleanup is caller-owned, preventing double-free.