LEFT$ function

Purpose:

LEFT$ returns the leftmost substring of a string.

Syntax:

SubStr = LEFT$(MainStr AS STRING, Length AS INTEGER)

Return Value:

  • Data type: STRING
    SubStr Substring of MainStr.

Parameters:

  • Data type: STRING
    MainStr String from which left substring is to be copied.
  • Data type: INTEGER
    Length Leftmost substring length.

Example:

CLS

DIM Substr AS STRING

DIM MainStr AS STRING

DIM StartPos AS INTEGER

DIM Length AS INTEGER

MainStr = "OneTwoThree"

Length = 3
Substr = LEFT$(MainStr, Length)
PRINT Substr

StartPos = 4
Substr = MID$(MainStr, StartPos, Length)
PRINT Substr

Length = 5
Substr = RIGHT$(MainStr, Length)
PRINT Substr

PAUSE

END

Result:

One
Two
Three

Press any key to continue . . .

BCX Console Sample Programs using the LEFT$ function.


LEFTSTR function

Purpose:

LEFTSTR searching from the left, returns TRUE if Match is a proper substring of MainStr or else FALSE if Match is not found.

Syntax:

RetVal = LEFTSTR(MainStr AS STRING, _
                   Match AS STRING  _
      [,CaseSensitivity AS INTEGER])

Return Value:

  • Data type: STRING
    RetVal If Match is a proper substring of MainStr, 1; if Match is not found, 0.

Parameters:

  • MainStr String in which substring is to be located.
  • Match Substring to be located.
  • CaseSensitivity [OPTIONAL] Default is 0 which is case sensitive. Set it to 1 for a case insensitive search.

Example:

DIM RetVal%

RetVal% = LEFTSTR("abcdefg", "abcd")

PRINT RetVal%

Result:

1