String
Strings in CrossBasic represent sequences of Unicode characters. They are enclosed in double quotes (").
- Declaration & Initialization
- Concatenation Use the
+operator to join strings:
Dim first As String = "Cross"
Dim second As String = "Basic"
Dim combined As String = first + second // "CrossBasic"
- Common String Functions
| Function | Description | Example |
|---|---|---|
Len(s) | Returns the length of s | Len("Hi") → 2 |
Left(s, n) | First n characters of s | Left("Basic", 3) → "Bas" |
Right(s, n) | Last n characters of s | Right("Basic", 2) → "ic" |
Mid(s, i, [n]) | n chars from position i (1‑based) | Mid("CrossBasic", 6, 5) → "Basic" |
Instr(s, sub) | Position of sub in s | Instr("Hello", "l") → 3 |
Replace(s, old, new) | Replace all old with new in s | Replace("a-b-a", "a", "x") → "x-b-x" |
Split(s, delim) | Returns array of substrings split by delim | Dim arr = Split("a,b,c", ",") |
Join(arr, delim) | Joins array of strings into one string | Join({"a","b"}, "-") → "a-b" |