String Operations

About array type references of strings

By using [], you can get one character in the string or replace the character at the specified position.

Example

A$="12345" 
A$[3] → "4" 
A$[3]="ABC" → "123ABC5" 

ASC(String)

Get the character code of the first character of the string

Argument

String

A string with the first character you want to check

Return Value

The character code of the specified character

Example

A=ASC("A")
X=ASC("XYZ")

CHR$(CharacterCode)

Return a character from a specified character code

・It can be used in constant expressions.

Argument

CharacterCode

Character code of the character you want to get

Return Value

One string corresponding to the character code

Example

S$=CHR$(65)

VAL(String)

Convert a string representing a number into a numeric value

Argument

String

String representing a number ("123" etc.)

Return Value

Numeric value interpreted from character string

Example

A=VAL("123")
F=VAL("-12.56")

STR$(NumericValue[,NumberOfDigits])

Convert numeric value to string

Arguments

NumericValue

The number you want to convert to a string

NumberOfDigits

Specified when you want to right align with the specified number of digits: 0 to 63

・If the number of digits of the numerical value is larger than the specified number of digits, the specification is ignored.
・When 0 is specified, no alignment is performed.
・0, if not specified.

Return Value

Converted string (123 → "123")

Example

S$=STR$(123)

HEX$(NumericValue[,NumberOfDigits])

Convert a numeric value to a hexadecimal string

Arguments

NumericValue

Numerica value to be converted to hexadecimal string

・If a Real is specified, the decimal part is rounded toward zero.

NumberOfDigits

Number of degits with a hexadecimal character string to be output: 0 to 8

・If a value of 1 or more is specified, a string with placing 0 at the beginning is returned.
・When 0 is specified, 0 is not placed at the beginning.
・0, if not specified.

Return Value

Conversion result hexadecimal string

Example

S$=HEX$(65535,4)

BIN$(NumericValue[,NumberOfDigits])

Convert a numeric value to a binary string

Arguments

NumericValue

Numeric value to convert to a binary string

・If a Real is specified, the decimal part is rounded toward zero.

NumberOfDigits

Number of digits with the a binary string to be output: 0 to 32

・If a value of 1 or more is specified, a string with placing 0 at the beginning is returned.
・When 0 is specified, 0 is not placed at the beginning.
・0, if not specified.

Return Value

Conversion result binary string

Example

S$=BIN$(65535,16)

FORMAT$(FormatString,Value,...)

Format the value into a string using the display format

Argument

FormatString

A string to be formatted and embedded

・Control the value formatting method by adding the following type specification or auxiliary specification after %.

%S Outputs the contents of a string variable
%D Decimal Int Output
%X Hexadecimal Int Output
%F Real Output
%B Binary Int Output
%% Output the Character %

Format string auxiliary specification

Format the output by specifying the following auxiliary specification after %

・Number of digits specification: Specify the number of digits (%8D,%4X)
・Specify the number of decimal places: The total number of digits, the number of digits in the decimal part (%8.2F)
・Blank padding: Specify a space character + number of digits (% 4D → "   0")
・Zero padding: Specify 0 + number of digits (%08D → "00000000")
・Left alignment: Specify -symbol + number of digits (%-8D)
・+Sign display: Specify +symbol + number of digits (%+8D)

Value

・Specify the value to be formatted and converted into a string as many arguments as the % specified in the format string (excluding %%).
・An error occurs if the % specification does not match with the type expected and the argument type.

Return Value

Generated string

Example

S$=FORMAT$("%06D",A)

LEN(String)
LEN(Array)

Get the number of characters in a string or the number of elements in an array

Argument

For String

A number of characters in a string you want to check

For Array

A number of elements in an array you want to check

Return Value

・For String: A number of characters
・For Array: A number of elements

Example

? LEN("ABC123")
DIM B[4]
? LEN(B)

LAST(String)
LAST(Array)

Return the subscript number at the end of a string or array

Argument

String or Array

String or array to check for the end

Return Value

Subscript number at the end

・For both strings and arrays, return the value obtained by subtracting 1 from the return value of the LEN function.

Example

DIM X[10]
FOR I=0 TO LAST(X)
 X[I]=I
NEXT

MID$(String,StartPosition [,NumberOfCharacters])

Get substring of the specified number of characters from specified position of the string

Arguments

String

Target string

StartPosition

Start position of the acquired string

NumberOfCharacters

Number of characters in the acquired string

・If not specified, the number of characters from the start position to the end of the string is specified.

Return Value

Obtained string

Example

S$=MID$("ABC",0,2)

LEFT$(String,NumberOfCharacters)

Get substrings of the specified number of characters from the beginning of the string

Arguments

String

Target string

NumberOfCharacters

Number of characters in the acquired string

Return value

Obtained string

Example

S$=LEFT$("ABC",2)

RIGHT$(String,NumberOfCharacters)

Get substring of the specified number of characters from the end of the string

Arguments

String

Target string

NumberOfCharacters

Number of characters in the acquired string

Return Value

Obtained string

Example

S$=RIGHT$("ABC",2)

INSTR(String,SearchString)
INSTR(StartPosition,String,SearchString)

Search the specified string in the string and return the position

Argument

StartingPosition

The position within the string to start the search

・If not specified, search from the beginning of the string.

String

Search target string

SearchString

The string to search for

Return Value

Found: Position in the string
Not found: -1

Example

A=INSTR(0,"ABC","B")

SUBST$(String,StartPosition,ReplacementString)
SUBST$(String,StartPosition,NumberOfCharacters,ReplacementString)

Create a new string by replacing part of the string

Arguments

String

Replace target string

StartPosition

Replacement start position

NumberOfCharacters

Number of characters to be replaced

・If not specified, all characters after the start position are replaced with the replacement string.

ReplacementString

Replace this string with the number of characters from the start position

Return Value

Replaced string

Example

A$=SUBST$("ABC",0,2,"XY")

DATE$()

Return current date as a string

Return Value

Current date string

・The format is "Year/Month/Day".

TIME$()

Return current time as a string

Return Value

Current time string

・The format is "Hour:Minute:Second".