Sheerpower Logo
F.2  String Manipulation Functions and Features
sheerpower provides a large set of string functions and features. All string functions are optimized for speed.

In business applications, strings are a fundamental data type used to represent and manipulate text-based information. From customer names and product descriptions to transaction details and log entries, strings are ubiquitous across various business processes. Due to the critical role strings play in these applications, the performance of string operations can significantly impact the efficiency of the entire system.

sheerpower’s Focus on String Efficiency:

sheerpower understands the importance of strings in business applications and has optimized its language to handle string operations with exceptional speed and efficiency. Whether it’s searching, comparing, concatenating, or transforming strings, sheerpower ensures that these operations are executed with minimal overhead.

Strings as buffers Strings can also be used store data into fixed length buffers. Over 30 million string overlays can be processed per second.
For example:
mybuf$ = space$(1024) subtext$ = 'abcde' start_pos = 1 for idx = 1 to 10 start_pos = overlay(mybuf$, subtext$, start_pos) next idx

For high-speed string bulding, sheerpower includes the JOIN() function. the format is:
new_pos = join(string_var$, string1$, string2$, ...) up to 15 strings at a time.
numbers$ = '' for i = 1 to 100_0000 newlen = join(numbers$, str$(i), ' ') next i print 'Length: '; len(numbers$) print 'Elapsed: '; _elapsed

String Function Documentation

Description:
The ASCII() function returns the decimal ASCII value of the first character in str_expr.

Arguments:
str_expr (required): The string whose first character's ASCII value is to be returned.

Example:
print ascii('A')
Output: 65

Description:
The BASE64ENCODE$() function encodes the provided text string str_expr into Base64 format. By default, it inserts a newline (CR/LF) every 76 characters. An optional boolean parameter can be used to control whether the newline is inserted.

Arguments:
str_expr (required): The string to be encoded.
boolean (optional): Set to FALSE to prevent the insertion of newlines. Defaults to TRUE.

Example 1: Simple Base64 encoding
print base64encode$('What is the base64 encoded version of this sentence?')
Output: V2hhdCBpcyB0aGUgYmFzZTY0IGVuY29kZWQgdmVyc2lvbiBvZiB0aGlzIHNlbnRlbmNlPw==

Example 2: Encoding with whitespace
print base64encode$(' Man ')
Output: ICAgIE1hbiA=

Example 3: Encoding without whitespace
print base64encode$('Man')
Output: TWFu

Example 4: Encoding with CRLF inserted
print base64encode$(repeat$('Hi there ', 50), true)
Output:
SGkgdGhlcmUgSGkgdGhlcmUgSGkgdGhlcmUgSGkgdGhlcmUgSGkgdGhlcmUgSGkgdGhlcmUgSGkgdGhl
cmUgSGkgdGhlcmUgSGkgdGhlcmUgSGkgdGhlcmUgSGkgdGhlcmUgSGkgdGhlcmUgSGkgdGhlcmUgSGkg
dGhlcmUgSGkgdGhlcmUgSGkgdGhlcmUgSGkgdGhlcmUgSGkgdGhlcmUgSGkgdGhlcmUgSGkgdGhlcmUg
SGkgdGhlcmUgSGkgdGhlcmUgSGkgdGhlcmUgSGkgdGhlcmUgSGkgdGhlcmUgSGkgdGhlcmUgSGkgdGhl
cmUgSGkgdGhlcmUgSGkgdGhlcmUgSGkgdGhlcmUgSGkgdGhlcmUgSGkgdGhlcmUgSGkgdGhlcmUgSGkg
dGhlcmUgSGkgdGhlcmUgSGkgdGhlcmUgSGkgdGhlcmUgSGkgdGhlcmUgSGkgdGhlcmUgSGkgdGhlcmUg

Example 5: Encoding without CRLF inserted
print base64encode$(repeat$('Hi there ', 50), false)
Output:
SGkgdGhlcmUgSGkgdGhlcmUgSGkgdGhlcmUgSGkgdGhlcmUgSGkgdGhlcmUgSGkgdGhlcmUgSGkgdGhl
cmUgSGkgdGhlcmUgSGkgdGhlcmUgSGkgdGhlcmUgSGkgdGhlcmUgSGkgdGhlcmUgSGkgdGhlcmUgSGkg
dGhlcmUgSGkgdGhlcmUgSGkgdGhlcmUgSGkgdGhlcmUgSGkgdGhlcmUgSGkgdGhlcmUgSGkgdGhlcmUg
SGkgdGhlcmUgSGkgdGhlcmUgSGkgdGhlcmUgSGkgdGhlcmUgSGkgdGhlcmUgSGkgdGhlcmUgSGkgdGhl
cmUgSGkgdGhlcmUgSGkgdGhlcmUgSGkgdGhlcmUgSGkgdGhlcmUgSGkgdGhlcmUgSGkgdGhlcmUgSGkg
dGhlcmUgSGkgdGhlcmUgSGkgdGhlcmUgSGkgdGhlcmUgSGkgdGhlcmUgSGkgdGhlcmUgSGkgdGhlcmUg

Description:
The BASE64DECODE$() function decodes a Base64 encoded string str_expr back into its original plain text format. To encode a string into Base64, see the BASE64ENCODE$() function.

Arguments:
str_expr (required): The Base64 encoded string to decode.

Example 1: Decoding a Base64 string
print base64decode$('V2hlbiBvbmUgZG9vciBjbG9zZXMsIGFub3RoZXIgb3BlbnM7IGJ1dCB3ZSBvZnRlbiBsb29rIHNv' +
'IGxvbmcgYW5kIHNvIHJlZ3JldGZ1bGx5IHVwb24gdGhlIGNsb3NlZCBkb29yIHRoYXQgd2UgZG8g' +
'bm90IHNlZSB0aGUgb25lIHdoaWNoIGhhcyBvcGVuZWQgZm9yIHVzLiAtQWxleGFuZGVyIEdyYWhh' +
'bSBCZWxs')

Output:
When one door closes, another opens; but we often look so long and so regretfully
upon the closed door that we do not see the one which has opened for us. -Alexander Graham Bell

Example 2: Decoding a short Base64 string
a$ = 'c3VyZQ=='
b$ = base64decode$(a$)
print b$
Output: sure

Description:
The BETWEEN$() function returns the string value between str_expr2 and str_expr3. If str_expr2 is empty, the function assumes the beginning of str_expr1. If str_expr3 is empty, the function assumes the end of str_expr1.

Arguments:
str_expr1 (required): The string to search within.
str_expr2 (required): The substring marking the start of the extraction.
str_expr3 (required): The substring marking the end of the extraction.

Example:
a$ = between$('the house was red', 'the ', ' was')
Output: 'house'
b$ = between$('size=30', '', '=')
Output: 'size'
c$ = between$('size=30', '=', '')
Output: '30'

Practical Uses:

  • Extracting Parameter Values from URLs:
    id_value$ = between$('http://example.com/page?id=1234&name=John', 'id=', '&')
    Result: '1234'
  • Parsing Log Entries:
    error_code$ = between$('ERROR[code=404]: Not Found', '[code=', ']')
    Result: '404'
  • Processing Formatted Data:
    size_value$ = between$('size=30', '=', '')
    Result: '30'
  • Extracting Substrings in Text Parsing:
    book_name$ = between$('The title of the book is [Moby Dick]', '[', ']')
    Result: 'Moby Dick'

Description:
The CHANGE$() function replaces characters in str_expr1 found in str_expr2 with the corresponding characters in str_expr3.

Arguments:
str_expr1 (required): The original string.
str_expr2 (required): The characters to be replaced.
str_expr3 (required): The replacement characters.

Example:
print change$('bdbdbdbd', 'b', 'c')
Output: cdcdcdcd

Description:
The CHARSET$() function returns a specified character set. Available sets include UCASE, LCASE, CONTROL, and ASCII.

Arguments:
str_expr (optional): The character set to return. Default is ASCII.

Example:
print charset$('ucase')
Output: ABCDEFGHIJKLMNOPQRSTUVWXYZ

Description:
The CHR$() function returns a string of ASCII characters corresponding to int_expr1. If int_expr2 is provided, the character is repeated that many times.

Arguments:
int_expr1 (required): The ASCII value of the character.
int_expr2 (optional): The number of times to repeat the character.

Example:
print chr$(65)
Output: A

Description:
The CONVERT$() function converts an integer int_expr1 into a string. An optional length int_expr2 can be specified, which defaults to four. The int_expr3 argument specifies the data type of the conversion. The supported data types are:

Data Types:

Data TypeConversion Result
1Integer (2 or 4 byte)
7COBOL comp-3 (C3 packed decimal)
17Packed floating (PF)

Arguments:
int_expr1 (required): The integer to convert.
int_expr2 (optional): The length of the resulting string.
int_expr3 (optional): The data type for conversion.

Example: Convert an integer to a string
a$ = convert$(16961)
print a$
Output: AB

Description:
The CONVERT() function converts a string containing a mapped integer back to its integer value.

Arguments:
str_expr (required): The string to convert.

Example:
print convert$('AB')
Output: 16961

Description:
The CPAD$() function pads a string on both sides with a specified character to reach a given size.

Arguments:
text_str (required): The string to pad.
size (required): The desired size of the final string.
pad_str (optional): The character to use for padding. Default is a space.

Example:
print cpad$('123', 9, '0')
Output: 000123000

Description:
The EDIT$() function performs one or more editing operations on the supplied string argument, depending on the value of the integer expression int_expr. The operations are determined by the values listed below. You can combine multiple operations by adding their corresponding values together.

Operation Values:

ValueEdit Operation
1Trim parity bits.
2Discard all spaces and tabs.
4Discard characters: CR, LF, FF, ESC, RUBOUT, and NULL.
8Discard leading spaces and tabs.
16Reduce multiple spaces and tabs to one space.
32Convert lower case to upper case.
64Convert "[" to "(" and "]" to ")".
128Discard trailing spaces and tabs.
256Do not alter characters inside quotes.

Arguments:
str_expr (required): The string to edit.
int_expr (required): The integer specifying the editing operation(s).

Example:
print edit$('hi there, how are you today?' , 32)
Output: HI THERE, HOW ARE YOU TODAY?

Description:
The ELEMENTS() function returns the number of elements in str_expr1, with elements separated by str_expr2 (default is a comma). The ELEMENT$() function returns a specific element from str_expr1 as specified by num_expr.

Arguments:
str_expr1 (required): The string containing the list of elements.
str_expr2 (optional): The separator between elements. Default is a comma.
num_expr (required for ELEMENT$): The index of the element to return.

Example:
print elements('a,b,c', ',')
Output: 3
print element$('a,b,c', 2)
Output: b

Description:
The ELEMENT$() function returns the element from str_expr1 specified by num_expr. The string str_expr1 contains a set of elements with separators between them. The optional str_expr2 specifies the separator between elements; if omitted, a comma is used as the default separator.

Arguments:
str_expr1 (required): The string containing the list of elements.
num_expr (required): The element number to return.
str_expr2 (optional): The separator between elements (default: comma).

Example 1: Get the 2nd element from a comma-separated list
let a$ = element$('ADD,DEL,EXIT', 2)
print a$
Output: DEL

Example 2: Use a space as the separator
let sentence$ = 'This is a test.'
let a$ = element$(sentence$, 2, ' ')
print a$
Output: is

Example 3: Handle multiple separators in a row
let sentence$ = 'This,, is, a, test'
print element$(sentence$, 2)
Output: [null]

Description:
The ENCODE$() function converts a number to a string in a specified base (e.g., binary, hexadecimal).

Arguments:
num_expr (required): The number to encode.
num_int (required): The base to convert to (e.g., 2 for binary, 16 for hexadecimal). Bases two through 36 are supported.

Example:
print encode$(255, 16)
Output: FF

Description:
For a detailed description, see: File Information Function

Arguments:
filename_str (required): The file name.

items_str: A comma separated list of requested items. 'Contents' returns the contents of the file.

Example:
print fileinfo$('@myfile.txt', 'device,name')
Output: c:myfile

Description:
The FORMAT$() function formats a given expression according to the specified format string str_expr. The expression can be of any data type, including strings.

Details:
The '@' format character causes the character not to be translated by the formatter.
The '<' and '>' characters are treated like an '@' character.
The FORMAT$() function can justify a character string, but zero suppression and zero insertion should be avoided.
If an overflow occurs, FORMAT$() returns a string of asterisks '*'.

Arguments:
expr (required): The expression to be formatted.
str_expr (required): The format string that specifies how to format the expression.

Example 1: Formatting a phone number
z$ = format$('5551234567', '(###)###~-####')
print 'Phone number: '; z$
Output: (555)123-4567

Example 2: Handling overflow
z$ = format$(12.23,'#.##')
print z$
Output: ****

Special Formats:
FORMAT$() supports the DATE format and date arguments. Given a date in YYMMDD or CCYYMMDD format, FORMAT$() returns the date in the specified format.

Example 3: Formatting a date
z1$ = format$('990122', '{date mdcy}?')
z2$ = format$('990122', '{date mdcy}##/##/####')
z3$ = format$('20000122', '{date mdcy}?')
z4$ = format$('20000122', '{date mdcy}##/##/####')
print z1$, z2$
print z3$, z4$
Output:
01221999 01/22/1999
01222000 01/22/2000

Date Arguments:

DATE ArgumentYYMMDD Input ResultCCYYMMDD Input Result
none1213199912132020
YMD991213201213
CYMD1999121320201213
MDY121399121320
MDCY1213199912132020
DMY131299131220
DMCY1312199913122020
DMONY13-Dec-9913-Dec-20
DMONCY13-Dec-199913-Dec-2020
MONTHDYDecember 13, 99December 13, 20
MONTHDCYDecember 13, 1999December 13, 2020

Special Features:
FORMAT$() also supports character rotation. The {ROTATE n} option rotates the last n characters of a string to the first position in the string.
FORMAT$(z$, '{ROTATE n}?')
The ? can be replaced with a mask.

Description:
The GEODISTANCE() function calculates the straight-line distance (as the crow flies) in miles between two geographic points specified by their latitude and longitude coordinates. The function takes two string expressions, str_expr1 and str_expr2, which contain the comma-separated latitude and longitude coordinates of the two points.

Details:
The calculated distance is rounded to three decimal points. If invalid or blank coordinates are provided, the function returns a default value of 99999 miles instead of throwing an exception.

Note:
The distance is calculated using Vincenty solutions of geodesics on an ellipsoid, which provides high accuracy for calculating distances on the Earth's surface.

Arguments:
str_expr1 (required): The first point's latitude and longitude, comma-separated.
str_expr2 (required): The second point's latitude and longitude, comma-separated.

Example 1: Calculating the distance between two points
here$ = '37.423021,-122.083739'
there$ = '42.730287,-73.692511'
miles = geodistance(here$, there$)
print 'Distance is: '; miles; ' miles'
Output: Distance is: 2555.453 miles

Description:
The GETSYMBOL$() function retrieves the value of script variables and symbols in sheerpower. These can include results from HTML form submissions, CGI environment variables, sheerpower symbols, DNS symbols, operating system symbols, or any custom-defined symbols.

Details:
The function has an optional boolean parameter that controls whether leading and trailing spaces are trimmed from the returned value. By default, this parameter is set to TRUE, which trims the spaces. If set to FALSE, the spaces are preserved.

Arguments:
str_expr1 (required): The name of the symbol to retrieve.
boolean (optional): Controls trimming of leading and trailing spaces. Defaults to TRUE.

Example 1: sheerpower Symbol with Trimming Option
set system, symbol 'test': value ' hi there'
print '<'; getsymbol$('sp:test'); '>'
print '<'; getsymbol$('sp:test', false); '>'
print '<'; getsymbol$('sp:test', true); '>'
Output:
<hi there>
< hi there>
<hi there>

Example 2: HTML Form Submission
// Print the contents of the symbol "city" from an HTML form submit.
print getsymbol$('city')

Example 3: CGI Environment Symbol
// Print the contents of the environment symbol REMOTE_ADDR
print getsymbol$('env:REMOTE_ADDR')

Example 4: Operating System Symbol
// Print the contents of the operating system symbol PATH
print getsymbol$('os:PATH')
// List the contents of the TEMP directory
print getsymbol$('os:TEMP')
Output:
C:\PROGRA~1\Java\JRE16~2.0_0\bin;C:\PROGRA~1\Java\JRE16~2.0_0\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\PROGRA~1\ABSOLU~1;C:\Program Files\QuickTime\QTSystem\;C:\Program Files\IDM Computer Solutions\UltraEdit\;C:\Program Files\IDM Computer Solutions\UltraCompare;.
C:\DOCUME~1\User\LOCALS~1\Temp

Supported Symbol Prefixes:

Symbol PrefixDescription
env:CGI environment variables
os:Operating system symbols. If the symbol begins with a \ then it is a registry symbol.
sp:sheerpower symbols
dns:DNS symbols

Description:
The GETWORD$() function extracts the word at position num_expr in str_expr1. Words are delimited by spaces or a custom separator defined by str_expr2.

Arguments:
str_expr1 (required): The string containing the words.
num_expr (optional): The index of the word to extract.
str_expr2 (optional): The custom separator. Default is a space.

Example:
print getword$('123rd Baker Street Apt 200', 2)
Output: 123rd

Description:
The HASH$() function converts the plain text in str_expr1 into a hashed eight-byte string value. This function is useful for creating one-way hashed passwords. To further enhance the uniqueness of the hashed value, you can optionally provide a second text string str_expr2 (known as a "salt") and an integer int_expr.

Details:

  • str_expr1 (required): The plain text to be hashed.
  • str_expr2 (optional): Additional text used to "salt" the hash, enhancing uniqueness.
  • int_expr (optional): A salt integer, which further ensures the uniqueness of the hash.
  • 3 (optional): Specifies the use of "Prime Hashing," which produces a 16-digit hex string suitable for use as a table key.
The PHASH$() function, which uses a different and faster hashing method, is recommended over HASH$(). For more information, refer to Section 6.4.33, PHASH$(str_expr [, int_expr]).

Example 1: Basic Hashing
password$ = hash$('TRUTH')
input 'Password': pwd$
if hash$(pwd$) = password$ then
  print 'That was the correct password.'
else
  print 'That was not the correct password.'
end if
Output:
password? MONEY
That was not the correct password.

Example 2: Hashing with Salt
password$ = hash$('TRUTH', 'someText', 1456)
print password$
Output:
MfatLÿ

Example 3: Prime Hashing with No Salt Integer
The optional 3 value specifies "Prime Hashing," which returns a 16-digit hex string that is very useful as a table key. If you use Prime Hashing without a salt integer, you must specify a salt of 0.
password$ = hash$('TRUTH', 'someText', 0, 3)
print password$
Output:
C8F0BE24C5880368

Description:
The HTMLDECODE$() function decodes an HTML encoded string into its corresponding characters.

Arguments:
str_expr (required): The HTML encoded string.

Example:
print htmldecode$('<html>')
Output:

Description:
The HTMLENCODE$() function encodes a string for safe use in HTML, replacing special characters with their HTML equivalents.

Arguments:
str_expr (required): The string to encode.

Example:
print htmlencode$('This is an tag')
Output: This is an <html> tag

Description:
The JOIN() function concatenates up to 16 string expressions and assigns the result to the first string expression. The function is highly optimized for speed, making even repeated calls with just two parameters very fast.

Arguments:
str_expr1 (required): The first string expression that will hold the concatenated result.
str_expr2 to str_expr16 (optional): Additional string expressions to be concatenated.

Return Value:
The function returns the length of the new concatenated string.

Example:
a$ = "Well, "
b$ = "fred"
z = join(a$, "hi ", "there ", b$)
print a$
Output: Well, hi there fred

Notes:
You can pass up to 16 parameters at a time to JOIN(). However, the function is designed to be very fast, even when used repeatedly with just two parameters.

Description:
The LCASE$() function converts all letters in str_expr to lowercase.

Arguments:
str_expr (required): The string to convert to lowercase.

Example:
print lcase$('IT HAS BEEN A WONDERFUL DAY!')
Output: it has been a wonderful day!

Description:
The LEFT$() function returns the leftmost characters from str_expr, up to the position specified by int_expr.

Arguments:
str_expr (required): The string to extract from.
int_expr (required): The number of characters to extract from the left.

Example:
print left$('Hello there!', 3)
Output: Hel

A negative number truncates the result:
a$='abcdefghij'
print left$(a$,-3)
Output: abcdefg

Description:
The LEN() function returns the length of str_expr as an integer.

Arguments:
str_expr (required): The string whose length is to be calculated.

Example:
print len('These are the built-in functions of sheerpower.')
Output: 47

Description:
The LPAD$() function pads text_str on the left with the specified character to reach the specified size. The default pad character is a space.

Arguments:
text_str (required): The string to pad.
size (required): The desired size of the final string.
pad_str (optional): The character to use for padding. Default is a space.

Example:
print lpad$('123', 6, '0')
Output: 000123

Description:
The LTRIM$() function removes all leading white space from str_expr.

Arguments:
str_expr (required): The string to trim.

Example:
print ltrim$(' This function removes leading white space.')
Output: This function removes leading white space.

Description:
The MATCHWORD() function returns the character position of the word or phrase specified in str_expr2 within the string str_expr1. The function performs a case-insensitive search and works with both single words and phrases.

Details:

  • str_expr1 (required): The string in which to search for the word or phrase.
  • str_expr2 (required): The word or phrase to find within str_expr1.
  • num_expr (optional): The starting position for the text scan. The default is 1.
If the word or phrase is found, the function returns the character position within the string. If not found, it returns 0. After calling MATCHWORD(), the special variable _integer contains the word index number, indicating which word in the list was matched.

Example: Searching for a Word
print matchword('list of words or 11111 numbers', 'Words')
print _integer
Output:
14
3
Explanation: The word "Words" starts at character position 14 in the string, and it is the 3rd word in the list.

Description:
The MAXLEN() function returns the maximum number of characters that a string variable can contain. For sheerpower string variables, this is always 2147450880.

Arguments:
str_var (required): The string variable to check.

Example:
print maxlen('Hi')
Output: 2147450880

Description:
The MEM() function returns a zero-terminated string from the specified memory address.

Arguments:
int_memory_address (required): The memory address to read from.

Example:
library 'msvcrt.dll'
call 'ctime' (0%)
mytime$ = mem(_integer)
Output: -- Wed Dec 31 16:00:00 1969

Description:
The MID$() function returns a substring from str_expr, starting at int_expr1 for a length of int_expr2 characters. If int_expr2 is omitted, the substring from int_expr1 to the end of the string is returned.

Arguments:
str_expr (required): The string to extract from.
int_expr1 (required): The starting position.
int_expr2 (optional): The length of the substring.

Example:
print mid$('beginmiddleend', 6, 6)
Output: middle

Description:
The ORD() function returns the ASCII value of the first character in str_expr.

Arguments:
str_expr (required): The character to find the ASCII value of.

Example:
print ord('H')
Output: 72

Description:
The ORDNAME$() function returns the character for the specified ASCII value.

Arguments:
int_expr (required): The ASCII value to convert to a character.

Example:
print ordname$(69)
Output: E

Description:
The PARSE$() function splits a string into tokens, returning each token separated by a space. Letters are uppercased except within quotes, and tail comments are ignored.

Arguments:
str_expr (required): The string to parse.

Example:
print parse$('company$ = 123abc$ + "and sons" !rnn')
Output: COMPANY$ = 123ABC$ + "and sons"

Description:
The PHASH$() function creates a salted hash of str_expr using an optional int_expr for additional uniqueness. The result is a 24-character string that is URL-safe.

Arguments:
str_expr (required): The string to hash.
int_expr (optional): An integer to further randomize the hash.

Example:
print phash$('TRUTH', 23993)
Output: fbOdJCu87od9s50kK7zuh32W

Description:
The PIECES() function returns the number of elements in str_expr1, separated by str_expr2 (default is CR/LF). The PIECE$() function returns a specific piece of str_expr1 as specified by num_expr.

Arguments:
str_expr1 (required): The string to extract from.
str_expr2 (optional): The separator between elements. Default is CR/LF.
num_expr (required for PIECE$): The index of the piece to return.

Example:
print pieces('line1\r\nline2\r\nline3', '\r\n')
Output: 3
print piece$('line1\r\nline2\r\nline3', 2)
Output: line2

Description:
The PRETTY$() function converts text so that control characters are displayed with their names or hexadecimal values, making the text displayable on any terminal.

Arguments:
str_expr (required): The text to convert.

Example:
print pretty$('Hello' + chr$(5) + chr$(161) + chr$(7))
Output: Hello{^E}{A1}{bel}

Description:
The QUOTE$() function encloses str_expr in double quotes. If the string is already quoted, QUOTE$() leaves it as is, but converts single quotes to double quotes.

Arguments:
str_expr (required): The string to quote.

Example:
print quote$('The little boy cried "wolf!"')
Output: "The little boy cried ""wolf!"""

Description:
The REPEAT$() function repeats str_expr int_expr times.

Arguments:
str_expr (required): The string to repeat.
int_expr (required): The number of times to repeat the string.

Example:
print repeat$('Hi!', 9)
Output: Hi!Hi!Hi!Hi!Hi!Hi!Hi!Hi!Hi!

Description:
The REPLACE$() function searches for patterns in str_expr1 and replaces them with the output from str_expr2. Optional separators str_sep1 and str_sep2 can be specified.

Arguments:
str_expr1 (required): The string containing the patterns to replace.
str_expr2 (required): The string containing the replacement patterns.
str_sep1 (optional): Separator for replacement items. Default is a comma.
str_sep2 (optional): Separator between input and output text in items. Default is =.

Example:
print replace$('01-Mar-1989', 'Mar=Jun')
Output: 01-Jun-1989

Description:
For a detailed description, see: Regular Expression Text Replacement

Arguments:
text_str (required): The text to operate on.

expr_str: The regular expression to use.

new_str: The new text to use.

Example:
print regexreplace$('The rain in Spain', 'rain', 'snow')
Output: c:myfile

Description:
The RIGHT$() function returns the rightmost characters from str_expr, up to the position specified by int_expr.

Arguments:
str_expr (required): The string to extract from.
int_expr (required): The number of characters to extract from the right.

Example:
print right$('Daniel', 2)
Output: el

Description:
The RPAD$() function pads text_str on the right with the specified character to reach the specified size. The default pad character is a space.

Arguments:
text_str (required): The string to pad.
size (required): The desired size of the final string.
pad_str (optional): The character to use for padding. Default is a space.

Example:
print rpad$('123', 6, '0')
Output: 123000

Description:
The RTFENCODE$() function encodes text for use in RTF files, ensuring that the content does not interfere with existing RTF code.

Arguments:
str_expr (required): The text to encode.

Example:
print rtfencode$('{\\rtf1\\ansi\\deff0 {\\fonttbl {\\f0 Courier;}}')
Output: \'7B\'5Crtf1\'5Cansi\'5Cdeff0 \'7B\'5Cfonttbl \'7B\'5Cf0 Courier;\'7D\'7D

Description:
The RTFDECODE$() function decodes text that has been encoded for use in RTF files.

Arguments:
str_expr (required): The RTF encoded string to decode.

Example:
print rtfdecode$("\'7B\'5Crtf1\'5Cansi\'5Cdeff0 \'7B\'5Cfonttbl \'7B\'5Cf0 Courier;\'7D\'7D")
Output: {\rtf1\ansi\deff0 {\fonttbl {\f0 Courier;}}}

Description:
The RTRIM$() function removes all trailing white space from str_expr.

Arguments:
str_expr (required): The string to trim.

Example:
let a$ = ' HELLO '
print rtrim$(a$)
Output: HELLO

Description:
The SEG$() function extracts a substring from str_expr using int_expr1 as the starting position and int_expr2 as the ending position.

Arguments:
str_expr (required): The string to extract from.
int_expr1 (required): The starting position.
int_expr2 (required): The ending position.

Example:
print seg$('abcdefghijklmnop', 3, 8)
Output: cdefgh

Description:
The SORT$() function sorts the elements in str_expr1 based on their ASCII values. str_expr2 can be used to specify the separator between elements.

Arguments:
str_expr1 (required): The string containing the elements to sort.
str_expr2 (optional): The separator between elements. Default is a comma.

Example:
print sort$('code area is', ' ')
Output: area code is

Description:
The SPACE$() function returns a string consisting of num_expr spaces.

Arguments:
num_expr (required): The number of spaces to return.

Example:
print space$(10)
Output: (10 spaces)

Description:
The STR$() function converts num_expr to a string without adding any extra spaces.

Arguments:
num_expr (required): The number to convert.

Example:
print str$(22)
Output: 22

Description:
The TAB() function moves the cursor to the column specified by int_expr. It is often used with the PRINT statement for formatting output.

Arguments:
int_expr (required): The column number to move the cursor to.

Example:
print tab(20); 'Hello there!'
Output: (spaces up to column 20) Hello there!

Description:
The TRIM$() function removes both leading and trailing white space from str_expr.

Arguments:
str_expr (required): The string to trim.

Example:
let a$ = ' HELLO '
print trim$(a$)
Output: HELLO

Description:
The TYPEOF$() function is used to determine the primitive data type and any custom type of a variable. This can be particularly useful in generic routines where developers may want to use specific logic based on the data type of the variables passed in.

Arguments:
variable (required): The variable whose type is being queried.

Return:
The function returns a string with the format "Name:VariableName, Dtype:DataType, Ctype:CustomType" if a custom type is defined, or just "Name:VariableName, Dtype:DataType" if no custom type is defined.

Example Usage:

a$ = 'hi' print typeof$(a$) // Output: Name:A$, Dtype:String age = 56 print typeof$(age) // Output: Name:AGE, Dtype:Real type feet real declare feet mysize mysize = 6 print typeof$(mysize) // Output: Name:MYSIZE, Dtype:Real, Ctype:FEET

Example Usage in a Routine:

This example shows how the TYPEOF$() function can be used in a temperature conversion routine that always outputs temperatures in Fahrenheit, even if the input is in Celsius.

routine convert_to_fahrenheit with temperature, returning result if pos(typeof$(temperature), "Ctype:CELSIUS") > 0 then result = (temperature * 9 / 5) + 32 else result = temperature // Assume input is already in Fahrenheit end if end routine type celsius real declare celsius temperature temperature = 100 convert_to_fahrenheit with temperature, returning result print 'Result in fahrenheit: '; result

Description:
The UCASE$() function converts all letters in str_expr to uppercase.

Arguments:
str_expr (required): The string to convert to uppercase.

Example:
print ucase$('are you enjoying this manual so far?')
Output: ARE YOU ENJOYING THIS MANUAL SO FAR?

Description:
The UNQUOTE$() function removes one set of quotes from str_expr. If the string is not quoted, UNQUOTE$() leaves it unchanged.

Arguments:
str_expr (required): The string to unquote.

Example:
print unquote$('I will not take these ''things'' for granted.')
Output: I will not take these 'things' for granted.

Description:
The URLENCODE$() function converts a string into a format that can be safely used in a URL. Spaces are converted to + signs, and special characters are encoded as hexadecimal values.

Arguments:
str_expr (required): The string to encode.

Example:
print urlencode$('Dogs & cats')
Output: Dogs+%26+cats

Description:
The URLDECODE$() function decodes a URL-encoded string back to its original text, converting + signs back to spaces and hexadecimal values to their corresponding characters.

Arguments:
str_expr (required): The URL-encoded string to decode.

Example:
print urldecode$('Dogs+%26+cats')
Output: Dogs & cats

Description:
The UUID$() function generates a "universally unique identifier" (UUID) that can be used as a unique key for a table. It ensures that key values are sparse, making them difficult to guess or enter accidentally.

Details:
The function can be called with no parameters or with a single parameter that specifies the format, with the default format being 0. Additionally, a third parameter can be used to specify the total desired return length, in which case multiple UUIDs are generated and concatenated until the specified length is achieved.

Formats:

  • 0: 32 hex digits made from the 128-bit UUID in memory byte order. This format is very fast (over 3 million/sec) and is the default if no parameter is given.
  • 1: 32 hex digits in RFC-specified order, allowing meaning to be attached to the hex digits (about 900,000/sec).
  • 2: 32 hex digits grouped with four dashes (about 900,000/sec), resulting in 36 characters in total.
  • 3: Similar to format 2 but with additional braces at the front and back. This is the standard display format for a UUID, resulting in 38 characters in total.

Example:
print uuid$
print uuid$(0) // base64-encoded UUID (default), is the same as UUID$
print uuid$(1) // UUID in hex digits
print uuid$(2) // UUID in hex with dashes
print uuid$(3) // UUID in hex with dashes, enclosed with braces
Sample results:
_Tgn05ms3UeHyarCf8zSlg
Rcy4J8f3306y05huwMOtSA
B6C33FB8253D46038E07C00A8002D9F7
C126D0DF-959D-4954-B581-F505AB9DD541
{43FB8797-E2A8-42A3-8B8B-9B391C45F850}

Notes:
The default UUID format returns 22 bytes, achieved by converting the 128-bit standard internal UUID into a base-64 encoded string, then stripping off the trailing two "=" characters. For URL safety, "+" is changed to "-" and "/" to "_". UUIDs are also known as GUIDs (Globally Unique Identifiers). For more information on UUIDs, visit: Wikipedia on UUIDs.

Description:
The VAL() function converts num_str to a REAL value. For a more detailed description, see: Extracting Numbers From Text -- Strings to Reals

Arguments:
num_str (required): The string to convert.

Example:
print val('4.567')
Output: 4.567

Description:
The WRAP$() function returns a word-wrapped version of str_expr, with each line of text wrapped between int_expr1 and int_expr2 margins.

Arguments:
str_expr (required): The string to wrap.
int_expr1 (required): The left margin.
int_expr2 (required): The right margin.

Example:
print wrap$('This is an example of the wrap$ function.', 5, 15)
Output:
This is an
example of
the wrap$
function.

Description:
The XLATE$() function translates characters in str_expr1 using a translation table specified by str_expr2.

Arguments:
str_expr1 (required): The string to translate.
str_expr2 (required): The translation table.

Example:
a$ = charset$()
a$[66:66] = 'x'
print xlate$('DAN', a$)
Output: DxN

Description:
The xor$() function returns a string where each bit is the result of a bit-wise XOR operation between the corresponding bits of str1$ and str2$. This function is useful for performing operations like OTP (One-Time Pad) encryption.

Arguments:
str1$ (required): The first string.
str2$ (required): The second string.

Example:
a$ = 'hi there'
k$ = uuid$(0, len(a$))
e$ = xor$(a$, k$)
print xor$(e$, k$)
Output: hi there


The code below contains examples of some of the major string functions.

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.
Wide screen