MID$ - QB64 Wiki

MID$

From QB64 Wiki

Revision as of 22:33, 20 September 2012 by Clippy (Talk | contribs)
(diff) ← Older revision | Current revision (diff) | Newer revision → (diff)
Jump to: navigation, search

The MID$ function returns a portion of a STRING's value from any position inside a string.


Syntax:

MID$(stringvalue$, startposition%[, bytes%])


Parameters:

  • stringvalue can be any literal or variable STRING value having a length. See LEN.
  • startposition designates the non-zero position of the first character to be returned by the function.
  • bytes (optional) tells the function how many characters to return including the first character when it is used.

Usage:

  • When the bytes value is not used the function returns the remainder of the string from the starting character position.
  • Number of character bytes should be within the string's length from the start position, but will only return the string's remainder when exceeded.
  • If the bytes value is 0 or the start position is 0 or greater than the length of the string, nothing is returned (no error).
  • In QBasic the start position cannot be zero(0) or an Illegal function call error will occur.


Example: Getting the hour and minutes from TIME$

PRINT TIME$ hour$ = LEFT$(TIME$, 2) minutes$ = MID$(TIME$, 4, 2) ' skip hours and the colon (3 characters) PRINT "hour = "; hour$; ": minutes = "; minutes$

11:23:30 hour = 11: minutes = 23


See also:



Navigation:
Go to Keyword Reference - Alphabetical
Go to Keyword Reference - By usage
Go to Main WIKI Page