User Tools

Site Tools

한국어

cubloc:string_functions:index

String Functions

String functions are provided to assist the user in accessing and modifying data within a String.

DP(value, numberOfDigits, zeroPrint)

DP converts a variable into a decimal string representation.

If zeroPrint is set to 1, zeros are printed instead of blank spaces.

Dim A as Integer
Debug DP(A,10,0)      ' Convert A into decimal String representation.
                      ' Set display decimalPlaces to 10.
                      ' If A is 1234, " 1234" will be displayed.
                      ' (notice the 6 blank spaces)
Debug DP(A,10,1)      ' If A is 1234, 0000001234 will be displayed.

HP(value, numberOfDigits, zeroPrint)

HP converts a variable into a hexadecimal string representation. If ZeroPrint is set to 1, zeroes are substituted for blank spaces.

Debug HP(A,4,0)       ' Convert A into HEX String representation
                      ' Set display decimal places to 4.
                      ' If A is ABC, bABC will be displayed.
                      ' (b stand for blank spaces.)
Debug HP(A,4,1)       ' If A is ABC, 0ABC will be displayed.

FP (value, wholeNumberDigits,fractionalNumberDigits)

FP converts floating point variables into a formatted string with user defined whole and fractional number of digits.

Dim A as Single
A = 3.14
Debug Float A           ' 3.1400000 Prints all digits.
Debug FP(A,3,2)         ' 3.14 Print user defined digits.

With the FP function, the user can control the number of digits to be used for string data when using Debug or displaying to an LCD.

Cubloc floating-point values are stored in accordance to the IEEE724 format. The output of FP and Float may differ but the value stored in the variable will be the same.

Left(stringValue, numberOfCharacters)

Returns a specified number of characters from the left side of a String

Dim ST1 As String * 12
ST1 = "CUBLOC"
Debug Left(ST1,4)           ' "CUBL" is printed.

Right(stringValue, numberOfCharacters)

Returns a specified number of characters from the right side of a String.

Dim ST1 As String * 12
ST1 = "CUBLOC"
Debug Right(ST1,4)           ' "BLOC" is printed.

Mid(stringValue, location, numberOfCharacters)

Returns a specified number of characters from a string starting at a specified location.

Dim ST1 As String * 12
ST1 = "CUBLOC"
Debug Mid(ST1,2,4)           ' "UBLO" is printed.

Len(stringValue)

Return the length of the given String.

Dim ST1 As String * 12
ST1 = "CUBLOC"
Debug Dec Len(ST1)         ' 6 is printed since there are 6 characters in ST1.

String(asciiCode, length)

Creates a String of a specified length with the given ASCII code repeated for the length of the String.

Dim ST1 As String * 12
ST1 = String(&H41,5)
Debug ST1              ' AAAAA is printed.
                       ' &H41 is ASCII code for character A.

SPC(numberOfSpaces)

Create a specified amount of blank space

Dim ST1 As String * 12
ST1 = SPC(5)
Debug "A",ST1,"A"      ' A A is printed.
                       ' Note the 5 blank spaced between each A.

LTrim(stringValue)

Removes all blank spaces from the left side of the given String.

Dim ST1 As String * 12
ST1 = " COMFILE"
ST1 = LTrim(ST1)
Debug "AAA",ST1      ' AAACOMFILE is printed.

RTrim(stringValue)

Removes all blank spaces from the right side of the given String.

Dim ST1 As String * 12
ST1 = "COMFILE "
ST1 = RTrim(ST1)
Debug ST1,"TECH"     ' COMFILETECH is printed.
                     ' Blank spaces on the right are removed.

Val(stringValue)

Parses a given String into its equivalent decimal value.

Dim ST1 As String * 12
Dim i As Integer
ST1 = "123"
i = Val(ST1)         ' 123 is stored in variable I as a number.

ValSng(stringValue)

Parses a given String into its equivalent floating point value.

Dim ST1 As String * 12
Dim F As Single
ST1 = "3.14"
F = ValSng(ST1)      ' 3.14 is stored in variable F as a floating point number.

ValHex(String variable)

Parses a given String in hexadecimal format into its numeric equivalent.

Dim ST1 AS String * 12
Dim i AS Long
ST1 = "ABCD123"
i = ValHex(ST1) '&HABCD123 is stored in variable I

Chr(asciiCode)

Return the character represented by the given ASCII code.

Dim ST1 AS String * 12
ST1 = Chr(&H41)
Debug ST1              ' Print A. &H41 is the ASCII code for character A.

ASC(stringValue)

Return ASCII code of the first character in the given String.

Dim ST1 AS String * 12
Dim i AS Integer
ST1 = "123"
i = Asc(ST1)          ' &H31 is stored in variable I. ASCII code of 1 is &H31 or 0x31.

Caution: A variable must be used when using string functions.

Debug Left("INTEGER",4)     ' A String constant cannot be used.
ST1 = "INTEGER"
Debug Left(ST1,4)           ' The String must be stored as a variable first.

Go CUBLOC home

cubloc/string_functions/index.txt · Last modified: 2016/04/14 11:07 (external edit)