Mid


Function Mid( string, start [, length] )


Returns a substring of string beginning at start, length characters long.


Syntax a = Mid( "Hello There", 1, 6 )


Remarks

Mid returns a substring of string, starting at start.

If the optional length parameter is supplied, then the returned string will be length bytes long.


Mid cannot be an LValue. In BASIC, and some other languages with a similar function, the statement Mid( a, 1, 1 ) = chr(34) would be legal.

This scripting language does not allow such assignments. Mid is an RValue ONLY.

It is easy enough to work around this limitation, see the example script for a way to accomplish the same result.


See Also:

Instr Left Right String Functions


Example Script


' This example will replace all whitespace ( tab, space, carriage return and line feed )

' characters in a string with the underscore ( '_' ).


STRING result,tmp = " This has some white space in it."

NUMBER i,j


FOR i = 1 TO LEN(tmp)

j = ASC(MID(tmp,i,1))

IF j == 9 OR j == 10 OR j == 13 OR j == 32 THEN

result = result + "_"

ELSE

result = result + MID(tmp,i,1)

ENDIF

NEXT i

PRINT result


Script Output


_This_has____some_white_space_in____it.