Mid$()


Mid$() may be used as a function or a command. As a function mid$() returns a specified number of characters from a sting. As a command mid$() replaces specified characters a source string.


sub$ = Mid$(str$, start {,len})

Used as a function Mid$() returns a string containing a specified number of characters from a string.

str$

The source string from which the characters are to be extracted.

start

The position of the first character to extract.

len

This optional parameter specifies the number of characters to extract. If not specified all the characters from start to the end of the string will be extracted.


For example:


str$ = "The dog jumps over"
Print mid$(str$, 5, 3)

dog

Print mid$(str$, 5)

dog jumps over




Mid$(str$, start {,len}) = ins$

Used as a command Mid$() replaces and inserts characters into a string.

str$

The source string of which characters are to be replaced.

start

The position of the first character to replace.

len

This optional parameter specifies the number of characters to replace. If not specified all the characters from start to the end of the string will be replaced.


For example:


str$ = "The dog jumped"
mid$(str$, 5, 3) = "fox"
Print str$

The fox jumps

mid$(str$, 5) = "cow"
Print str$

The cow

mid$(str$, 5) = "cow jumped over"
Print str$

The cow jumped over

mid$(str$, 5, 3) = "duck"
Print str$

The duck jumped over







Become a Patron