SmallBASIC GuideThe language | Programming Tips | Commands | System | Graphics & Sound | Miscellaneous | File system | Mathematics | 2D Algebra | Strings | Console | Glossary |
Function: SPC (n)
Function: SPACE (n) returns a string of 'n' spaces
Function: BIN (x) Returns the binary value of x as string.
Function: OCT (x) Returns the octal value of x as string.
Function: HEX (x) Returns the hexadecimal value of x as string.
Function: VAL (s) Returns the numeric value of string s.
Function: STR (x) Returns the string value of x.
Function: CBS (s)
Function: BCS (s) CBS() - converts (C)-style strings to (B)ASIC-style (S)trings BCS() - converts (B)ASIC-style strings to (C)-style (S)trings C-Style string means strings with \ codes *, On CBS() we cannot use the \" character but we can replace it with \x22 or \042.
Function: ASC (s) Returns the ASCII code of first character of the string s.
Function: CHR (x) Returns one-char string of character with ASCII code x.
Function: LOWER (s)
Function: LCASE (s)
Function: UPPER (s)
Function: UCASE (s) Converts the string s to lower/upper case
? LOWER("Hi"):REM hi
? UPPER("Hi"):REM HI

Function: LTRIM (s) Removes leading white-spaces from string s
? LEN(LTRIM("  Hi")):REM 2

Function: RTRIM (s) Removes trailing white-spaces from string s
Function: TRIM (s) Removes leading and trailing white-spaces from string s. TRIM is equal to LTRIM(RTRIM(s))
Function: SQUEEZE (s) Removes the leading/trailing and duplicated white-spaces
? "["; SQUEEZE(" Hi  there "); "]"
' Result: [Hi there]

Function: ENCLOSE (str[, pair]) Encloses a string. The default pair is ""
? enclose("abc", "()")
' Result: (abc)

Function: DISCLOSE (str[, pairs [, ignore-pairs]]) Discloses a string. Default pairs and ignore pairs
First
non white-space
character           Check   Ignore
--------------------------------------------
"                   ""      ''
'                   ''      ""
(                   ()      ""''
[                   []      ""''
                         ""''
<                   <>      ""''
Otherwise:
"                   ""      ''
s = "abc (abc)"
? s; tab(26); disclose(s, "()")
' prints abc
s = "abc (a(bc))"
? s; tab(26); disclose(s, "()"); tab(40); disclose(disclose(s, "()"), "()")
' prints a(bc), bc
s = "abc (a='(bc)')"
? s; tab(26); disclose(s, "()", "''"); tab(40); &
    disclose(disclose(s, "()", "''"), "()", "''")
' prints a='(bc)', nothing

Function: LEFT (s [,n])
Function: RIGHT (s[,n]) Returns the n number of leftmost/rightmost chars of string s If n is not specified, the SB uses 1
Function: LEFTOF (s1, s2)
Function: RIGHTOF (s1, s2) Returns the left/right part of s1 at the position of the first occurrence of the string s2 into string s1 *, s2 does not included on new string.
Function: LEFTOFLAST (s1, s2)
Function: RIGHTOFLAST (s1, s2) Returns the left/right part of s1 at the position of the last occurrence of the string s2 into string s1 *, s2 does not included on new string.
Function: MID (s, start [,length]) Returns the part (length) of the string s starting from 'start' position If the 'length' parameter is omitted, MID returns the whole string from the position 'start'.
Function: INSTR ([start,] s1, s2) Returns the position of the first occurrence of the string s2 into string s1 (starting from the position 'start') If there is no match, INSTR returns 0
Function: RINSTR ([start,] s1, s2) Returns the position of the last occurrence of the string s2 into string s1 (starting from the position 'start') If there is no match, RINSTR returns 0
Function: REPLACE (source, pos, str [, len]) Writes the 'str' into 'pos' of 'source' and returns the new string. This function replaces only 'len' characters. The default value of 'len' is the length of 'str'.
s="123456"
...
' Cut
? replace(s,3,"",len(s))
...
' Replace
? replace(s,2,"bcd")
...
' Insert
? replace(s,3,"cde",0)
...
' Replace & insert
? replace(s,2,"RRI",2)

Function: TRANSLATE (source, what [, with]) Translates all occurrences of the string 'what' found in the 'source' with the string 'with' and returns the new string.
? Translate("Hello world", "o", "O")
' displays: HellO wOrld

Function: CHOP (source) Chops off the last character of the string 'source' and returns the result.
Function: STRING (len, ascii|str) Returns a string containing 'len' times of string 'str' or the character 'ascii'.
Function: FORMAT (format, val) Returns a formatted string. Numbers: Strings:
? FORMAT("#,##0", 1920.6) : REM prints 1,921
? FORMAT("\  - \", "abcde") : REM prints "abc-de"

Command: SPRINT var; [USING...;] ... Create formatted string and storing it to var The syntax is the same with the PRINT command.
SPRINT s; 12.34; TAB(12); 11.23;
*, You can use 'USG' instead of 'USING'.
Command: SINPUT src; var [, delim] [,var [, delim]] ... Splits the string 'src' into variables which are separated by delimiters.
SINPUT "if x>1 then y"; vif, " ", vcond, "then", vdo
? vcond, vdo
' result in monitor
' x>1   y

Command: SPLIT string, delimiters, words() [, pairs] [USE expr] Returns the words of the specified string into array 'words' Example:
s="/etc/temp/filename.ext"
SPLIT s, "/.", v()
FOR i=0 TO UBOUND(v)
  PRINT i;" [";v(i);"]"
NEXT
'
displays:
0 []
1 [etc]
2 [temp]
3 [filename]
4 [ext]

Command: JOIN words(), delimiters, string Returns the words of the specified string into array 'words' Example:
s="/etc/temp/filename.ext"
SPLIT s, "/.", v()
JOIN v(), "/", s
PRINT "[";s;"]"
'
displays:
[/etc/temp/filename/ext]