MID$ statement

Purpose: Replaces a portion of a string with a substring.


 Syntax:

 MID$(MainStr$, Start% [, SubStrLen%]) = SubStr$

 Parameters:

  • MainStr$ String in which portion is replaced by SubStr$.
  • Start% Integer specifying the start position where SubStr$ is to be placed.
  • SubStr$ String literal or variable to replace portion of MainStr$.
  • SubStrLen% [OPTIONAL] Number of characters to copy from SubStr$.

Example:


 DIM str1$, str2$
 
 str1$ = "12345"
 str2$ = "abc"
 
 ' Copy the contents of str2$ to str1$
 ' starting at the 2nd character
   MID$(str1$, 2) = str2$
 
 PRINT str1$
 
 str1$ = "12345"
 str2$ = "abc"
 
 ' Copy only the first 2 characters of str2$ to str1$
 ' starting at the 2nd character.
   MID$(str1$, 2, 2) = str2$
 
 PRINT str1$

Result:



1abc5
1ab45

BCX Console Sample Programs using MID$ statement.

S62.bas