Skip to content

Functions Text

Paul Squires edited this page Nov 8, 2026 · 3 revisions

Home › Function Finder › Text

Text

The functions to search, slice, change, split and format strings, grouped by what you want to do. The From column says what a program needs before it can call one:

  • built-in: nothing; it is always available.
  • std/money: #import "std/money", then using money to call it by its bare name.
  • std/strings: #import "std/strings", then using strings to call it by its bare name.
  • string.bi: #include "string.bi".

Jump to: Find text in a string · Check what a string holds · Take part of a string · Change case · Trim, pad and align · Replace, insert and remove · Split and join · Build and wrap strings · Characters and their codes · Convert numbers to text · Convert text to numbers · Format money · Pack numbers into bytes and back

Find text in a string

Function What it does From
InStr Returns the position of the first match, or 0 if there is none. built-in
InStrRev Returns the position of the last match, or 0 if there is none. built-in
Contains Returns true if the text appears anywhere in the string. std/strings
Find Returns the position of the first match in a slice, counting from 0, or -1. std/strings
StartsWith Returns true if the string begins with the given text. std/strings
EndsWith Returns true if the string ends with the given text. std/strings
Tally Counts how many times the text occurs, without overlaps. std/strings
InstrChars Returns the position of the first character from a set, or 0. std/strings
TallyChars Counts the characters that belong to a set. std/strings

Check what a string holds

Function What it does From
Len Returns the length of a string, or the size of a type. built-in
Equals Returns true if two slices hold the same code units, optionally ignoring case. std/strings
IsBlank Returns true if the string is empty or holds only whitespace. std/strings
IsNumeric Returns true if the string is a valid number, with spaces allowed around it. std/strings
VerifySet Returns the position of the first character not in a set, or 0 if all are. std/strings
SpanOf Counts the run of characters from a set that starts at a position. std/strings

Take part of a string

Function What it does From
Left Returns the first n characters. built-in
Right Returns the last n characters. built-in
Mid Returns the characters from a position, optionally for a given length. built-in
Between Returns the text between two delimiters. std/strings
Extract Returns the text before a match, or the whole rest if there is none. std/strings
Remain Returns the text after a match, or an empty string if there is none. std/strings
ExtractChars Returns the text before the first character from a set. std/strings
RemainChars Returns the text after the first character from a set. std/strings

Change case

Function What it does From
UCase Returns an upper-case copy of the string. built-in
LCase Returns a lower-case copy of the string. built-in
MCase Returns a title-case copy: each word capitalised, the rest lower case. std/strings

Trim, pad and align

Function What it does From
Trim Removes spaces, or the given characters, from both ends. built-in
LTrim Removes spaces, or the given characters, from the start. built-in
RTrim Removes spaces, or the given characters, from the end. built-in
Shrink Trims both ends and collapses each inner run of spaces to one. std/strings
TrimSpace Returns a slice of the text without the spaces, tabs, CRs and LFs at either end. std/strings
TrimStart Returns a slice of the text without its leading spaces, tabs, CRs and LFs. std/strings
TrimEnd Returns a slice of the text without its trailing spaces, tabs, CRs and LFs. std/strings
PadLeft Pads on the left to a width, with spaces or a given character. std/strings
PadRight Pads on the right to a width, with spaces or a given character. std/strings
PadCenter Centres the string in a width, padding both sides. std/strings
LSet Copies a string into another, left-justified and padded with spaces. built-in
RSet Copies a string into another, right-justified and padded with spaces. built-in

Replace, insert and remove

Function What it does From
Replace Replaces every occurrence of the text with other text. std/strings
ReplaceChars Replaces each character from a set with one given character. std/strings
Remove Removes every occurrence of the text. std/strings
RemoveChars Removes every character that belongs to a set. std/strings
RetainChars Keeps only the characters that belong to a set. std/strings
RemoveBetween Removes a pair of delimiters and the text between them. std/strings
InsertAt Inserts text at a position. std/strings
DeleteAt Deletes a number of characters at a position. std/strings
ClipLeft Removes a number of characters from the start. std/strings
ClipRight Removes a number of characters from the end. std/strings
Mid (statement) Overwrites part of a string in place with other text. built-in

Split and join

Function What it does From
Split Breaks a string into an Array at each delimiter. std/strings
SplitSlices Walks the parts of a slice between separators, one at a time, in a for each loop. std/strings
SplitChars Breaks a string into an Array wherever a character from a set appears. std/strings
Join Joins an Array of strings into one, with a separator between them. std/strings
SplitCsv Parses CSV text into rows and fields, quoted fields included. std/strings
SplitCsvRow Parses one CSV record into an Array of fields. std/strings
JoinCsvRow Returns an Array of fields as one CSV record, quoting each field that needs it. std/strings
CsvWriter Writes CSV records to any fs.Stream as UTF-8, CRLF or LF line endings. std/strings

Build and wrap strings

Function What it does From
Space Returns a string of n spaces. built-in
WSpace Returns a wide string of n spaces. built-in
String Returns a string of n copies of one character. built-in
WString Returns a wide string of n copies of one character. built-in
Repeat Returns a string repeated n times. std/strings
Reverse Returns the string with its characters in reverse order. std/strings
Wrap Surrounds the string with quotes or a given pair of delimiters. std/strings
Unwrap Removes one surrounding pair of quotes or delimiters, if both are there. std/strings
Escape Replaces quotes, backslashes and control characters with backslash escapes. std/strings
Unescape Turns backslash escapes back into the characters they stand for. std/strings

Characters and their codes

Function What it does From
Asc Returns the character code at a position in a string. built-in
Chr Returns a string made from one or more character codes. built-in
WChr Returns a wide string made from one or more Unicode code points. built-in

Convert numbers to text

Function What it does From
Str Returns a number or boolean as text. built-in
WStr Returns a number as a wide string. built-in
Format Builds text from values with a format string such as "{:>6.2f}". std/strings
Format Formats a number with a picture string such as "#,##0.00". string.bi
Hex Returns a number as hexadecimal text. built-in
WHex Returns a number as hexadecimal wide-string text. built-in
Bin Returns a number as binary text. built-in
WBin Returns a number as binary wide-string text. built-in
Oct Returns a number as octal text. built-in
WOct Returns a number as octal wide-string text. built-in

Convert text to numbers

Function What it does From
Val Converts text to a double. built-in
ValInt Converts text to a 32-bit integer. built-in
ValLng Converts text to a 64-bit integer. built-in
ValUInt Converts text to an unsigned 32-bit integer. built-in
ValULng Converts text to an unsigned 64-bit integer. built-in

Format money

Function What it does From
MoneyFormat Holds an amount and prints it the way the user's locale writes money. std/money
MoneySetLocale Switches money formatting to a named locale; returns false if it is unknown. std/money
MoneyLocaleName Returns the name of the locale that money is formatted for. std/money
MoneyLocaleIsValid Returns false if the system rejected the money locale. std/money
MoneyRefreshLocale Rereads the locale's money settings after the user changes them. std/money
MoneyCompose Assembles a number, symbol and sign in one of the standard layouts. std/money
MoneyLayoutFromICurrency Converts a Windows positive-currency code into layout flags. std/money
MoneyLayoutFromINegCurr Converts a Windows negative-currency code into layout flags. std/money

Pack numbers into bytes and back

Function What it does From
MKI Copies an integer's bytes into a string. built-in
MKL Copies a Long's bytes into a 4-byte string. built-in
MKShort Copies a Short's bytes into a 2-byte string. built-in
MKLongInt Copies a LongInt's bytes into an 8-byte string. built-in
MKS Copies a Single's bytes into a 4-byte string. built-in
MKD Copies a Double's bytes into an 8-byte string. built-in
CVI Reads an integer back from a string of its bytes. built-in
CVL Reads a Long back from a 4-byte string. built-in
CVShort Reads a Short back from a 2-byte string. built-in
CVLongInt Reads a LongInt back from an 8-byte string. built-in
CVS Reads a Single back from a 4-byte string. built-in
CVD Reads a Double back from an 8-byte string. built-in

See Also


Home · Function Finder · Keyword Index

Clone this wiki locally