BRL.Retro: Functions Source  


The BASIC compatibility module provides miscellaneous functions that emulate the behaviour of 'classic' BASIC.

The functions in this module have largely been superceded by BlitzMax features such as 'string slicing', and the Find, Replace, Trim, ToLower and ToUpper string methods.

However, for programmers from a classic BASIC background, these utility functions should make the transition to BlitzMax a little easier.

NOTE: Strings in classic BASIC are '1 based'. This means that the first character within a string is at index 1, the second at index 2 and so on. However, BlitzMax strings are '0 based', meaning the first character is at index 0, the second at index 1 and so on. The instr and Mid functions in this module retain the '1 based' behaviour of classic BASIC.

Functions

MidExtract substring from a string
InstrFind a string within a string
LeftExtract characters from the beginning of a string
RightExtract characters from the end of a string
LSetLeft justify string
RSetRight justify string
ReplacePerforms a search and replace function
TrimRemove unprintable characters from ends a string
LowerConvert string to lowercase
UpperConvert string to uppercase
HexConvert an integer value to a hexadecimal string
BinConvert an integer value to a binary string
LongHexConvert a 64 bit long integer value to a hexadecimal string
LongBinConvert a 64 bit long integer value to a binary string

Function reference

Function Mid$( str$,pos,size=-1 )
ReturnsA sequence of characters from str starting at position pos and of length size
DescriptionExtract substring from a string
Information The Mid$ command returns a substring of a String.

Given an existing string, a position from the start of the string and an optional size, Mid creates a new string equal to the section specified. If no size if given, Mid returns the characters in the existing string from position to the end of the string.

For compatibility with classic BASIC, the pos parameter is 'one based'.

Function Instr( str$,sub$,start=1 )
ReturnsThe position within str of the first matching occurance of sub
DescriptionFind a string within a string
Information The start parameter allows you to specifying a starting index for the search.

For compatiblity with classic BASIC, the start parameter and returned position are both 'one based'.

Function Left$( str$,n )
Returnssize leftmost characers of str
DescriptionExtract characters from the beginning of a string
Information The Left$ command returns a substring of a String. Given an existing String and a size, Left$ returns the first size characters from the start of the String in a new String.

Function Right$( str$,n )
Returnssize rightmost characters of str
DescriptionExtract characters from the end of a string
Information The Right$ command returns a substring of a String. Given an existing String and a size, Right$ returns the last size characters from the end of the String.

Function LSet$( str$,n )
ReturnsA string of length n, padded with spaces
DescriptionLeft justify string

Function RSet$( str$,n )
ReturnsA string of length n, padded with spaces
DescriptionRight justify string

Function Replace$( str$,sub$,replaceWith$ )
ReturnsA string with all instances of sub$ replaced by replace$
DescriptionPerforms a search and replace function
Information The Replace$ command replaces all instances of one string with another.

Function Trim$( str$ )
Returnsstr with leading and trailing unprintable characters removed
DescriptionRemove unprintable characters from ends a string

Function Lower$( str$ )
ReturnsLowercase equivalent of str
DescriptionConvert string to lowercase

Function Upper$( str$ )
ReturnsUppercase equivalent of str
DescriptionConvert string to uppercase

Function Hex$( val )
ReturnsThe hexadecimal string representation of val
DescriptionConvert an integer value to a hexadecimal string

Function Bin$( val )
ReturnsThe binary string representation of val
DescriptionConvert an integer value to a binary string

Function LongHex$( val:Long )
ReturnsThe hexadecimal string representation of val
DescriptionConvert a 64 bit long integer value to a hexadecimal string

Function LongBin$( val:Long )
ReturnsThe binary string representation of val
DescriptionConvert a 64 bit long integer value to a binary string