Skip to content

BASIC String Functions

Curtis F Kaylor edited this page Jan 26, 2025 · 11 revisions

LEFT$

TYPE: BASIC String Function

FORMAT: LEFT$(string,integer)

Action: Returns a string comprised of the leftmost integer characters of the string. The integer argument value must be in the range 0 to 255. If the integer is greater than the length of the string, the entire string will be returned. If an integer value of zero is used, then a null string (of zero length) is returned.

Examples:
  10 A$ = "AQUARIUS COMPUTERS"
  20 B$ = LEFT$(A$,8): PRINT B$
  RUN

  AQUARIUS

MID$

TYPE: BASIC String Function

FORMAT: MID$(string,numeric-1[,numeric-2])

Action:

The MID$ function returns a sub-string which is taken from within a larger string argument. The starting position of the sub-string is defined by the numeric-1 argument and the length of the sub-string by the numeric-2 argument. Both of the numeric arguments can have values ranging from 0 to 255.

If the numeric-1 value is greater than the length of the string, or if the numeric-2 value is zero, then MID$ gives a null string value. If the numeric-2 argument is left out, then the BASIC will assume that a length of the rest of the string is to be used. If the source string has fewer characters than numeric-2, from the starting position to the end of the string argument, then the whole rest of the string is used.

EXAMPLE of MID$ Function:

10 A$="GOOD"
20 B$="MORNING EVENING AFTERNOON"
30 PRINT A$ + MID$(B$,8,8)

GOOD EVENING

RIGHT$

TYPE: BASIC String Function

FORMAT: RIGHT$(string,numeric)

Action: The RIGHT$ function returns a sub-string taken from the right-most end of the string argument. The length of the sub-string is defined by the numeric argument which can be any integer in the range of 0 to 255. If the value of the numeric expression is zero, then a null string ("") is returned. If the value you give in the numeric argument is greater than the length of the string then the entire string is returned.

EXAMPLES of RIGHT$ Function:

10 MSG$="Aquarius+ Computer"
20 PRINT RIGHT$(MSG$,8)
RUN

Computer

TRIM$

TYPE: plusBASIC v0.21x String Function

FORMAT: TRIM$ ( string )

Action: Trims white space characters from both ends of string.

  • string is the string to be trimmed.
  • Whitespace characters are characters with an ASCII value less than or equal to 32 (Space).
Examples:
TRIM$("   123   ")

Returns string 123

TRIM$("      ")

Returns string with length 0.

FORMAT: TRIM$(string,chars)

Action: As above, but trims the specified characters from each end of the string.

  • chars is a string containing a list of characters to be trimmed.
Examples:
TRIM$("@@@123@@@","@") 

Returns string 123.

TRIM$("@@@@@@","@") 

Returns string with length 0.

TRIM$("#*#abc#*#","*#")

Returns string abc.


TRIML$

TYPE: plusBASIC v0.21x String Function

FORMAT: TRIML$ ( string )

Action: As above but trims whitespace characters from the left end of the string.

Examples:
PRINT TRIML$("   123   ");"x" `

Returns string 123 .

TRIML$("      ")

Returns string with length 0.

FORMAT: TRIML$(string,chars)

Action: As above, but trims the specified characters from the left end of the string.

Examples:
TRIML$("@@@123@@@","@") 

Returns string 123@@@.

TRIML$("@@@@@@","@")

Returns string with length 0.

TRIML$("#*#abc#*#","*#")

Returns string abc#*#.


TRIMR$

TYPE: plusBASIC v0.21x String Function

FORMAT: TRIMR$ ( string )

Action: As above but trims whitespace characters from the left end of the string.

Examples:
TRIMR$("   123   ")

Returns string 123.

TRIMR$("      ")

Returns string with length 0.

FORMAT: TRIMR$(string,chars)

Action: As above, but trims the specified characters from the left end of the string.

Examples:
 TRIMR$("@@@123@@@","@")

Returns string @@@123.

TRIMR$("@@@@@@","@")

Returns string with length 0.

`'' TRIMR$("##abc##","*#") '''

Returns string #*#abc.


FILEDIR$

TYPE: plusBASIC v0.21i String Function

FORMAT: FILEDIR$ ( filespec )

Action: Returns the directory portion of a file specification.

  • filespec is a string containing the file specification.
  • Returns an empty string if the filespec does not contain directory name(s),
Examples:
FILEDIR$("file.ext")

Returns string with length 0.

FILEDIR$("/no_ext")

Returns string /

FILEDIR$("/a/b/file.tmp")

Returns string /a/b/

FILEDIR$("a/")

Returns string a/


FILEEXT$

TYPE: plusBASIC v0.21i String Function

FORMAT: FILEDIR$ ( filespec )

Action: Returns the extension portion of a filename.

  • filespec is a string containing the filename.
  • Returns an empty string if the filename does not contain and extension.
Examples:
FILEEXT$("file.ext")

Returns string ext

FILEEXT$("no_ext")

Returns string with length 0.

FILEEXT$("/a/b/file.tmp")

Returns string tmp

FILEEXT$("a/")

Returns string with length 0.


TRIMDIR$

TYPE: plusBASIC v0.21i String Function

FORMAT: TRIMDIR$ ( filespec )

Action: Returns a file specification with the directory portion removed.

  • filespec is a string containing the file specification.
  • Returns an empty string if filespec contains only directory name(s).
Examples:
TIMRDIR$("file.ext")

Returns string file.ext

TRIMDIR$("/no_ext")

Returns string no_ext

TRIMDIR$("/a/b/file.tmp")

Returns string file.tmp

TRIMDIR$("a/")

Returns string with length 0.


TRIMEXT$

TYPE: plusBASIC v0.21i String Function

FORMAT: TRIMEXT$ ( filespec )

Action: Returns a filename with the extension removed.

  • filespec is a string containing the filename.
  • Returns an empty string if filespec contains only an extension.
Examples:
TIMRDIR$("file.ext")

Returns string file

TRIMDIR$("/no_ext")

Returns string /no_ext

TRIMDIR$("/a/b/file.tmp")

Returns string /a/b/file

TRIMDIR$(".txt")

Returns string with length 0.

Clone this wiki locally