5.4.3.5 Mid/MidB/Mid$/MidB$ Statement

 mid-statement = mode-specifier "(" string-argument "," start ["," length] ")" "=" expression 
  
 mode-specifier = ("Mid" / "MidB" / "Mid$" / "MidB$") 
 string-argument = bound-variable-expression 
 start = integer-expression 
 length = integer-expression

Static Semantics.

  • The declared type of <string-argument> MUST be String or Variant.

 

Runtime Semantics.

  • If the value of <start> is less than or equal to 0 or greater than the length of <string-argument>, or if <length> is less than 0, runtime error 5 (Invalid procedure call or argument) is raised.

  • The data value of <string-argument> MUST be Let-coercible to String.

  • Let v be the data value that results from Let-coercing the data value of the evaluation of <expression> to the declared type String.

  • The new data value of the variable is identical to v except that a span of characters is replaced as follows:

    • If <mode-specifier> is "Mid" or "Mid$":

      • The first character to replace is the character at the 1-based position n within <string-argument>, where n = <start>. Starting at the first character to replace, the next x characters within <string-argument> are replaced by the first x characters of v, where x = the least of the following: <length>, the number of characters in <string-argument> after and including the first character to replace, or the number of characters in v.

    • If <mode-specifier> is "MidB" or "MidB$":

      • The first character to replace is the character at the 1-based position n within <string-argument>, where n = <start>. Starting at the first byte to replace, the next x bytes within <string-argument> are replaced by the first x bytes of v, where x = the least of the following: <length>, the number of bytes in <string-argument> after and including the first byte to replace, or the number of bytes in v.