-
Notifications
You must be signed in to change notification settings - Fork 8
mid
Anobium edited this page Oct 18, 2020
·
1 revision
Syntax:
output = Mid(source, start[, count])
Command Availability:
Available on all microcontrollers
Explanation:
The Mid
function returns a string variable containing a specified
number of characters from a source string.
source
is the variable to extract from. If source
is a zero length
string - a zero length string is returned equating to "".
start
is the position of the first character to extract. If start
is
greater than the number of characters in string, Mid returns a
zero-length string equating to "".
count
is the number of characters to extract. If count
is not
specified, all characters from start
to the end of the source string
will be returned.
Example:
'Set chip model
#chip 16F1936
'Set up hardware serial connection
#define USART_BAUD_RATE 9600
#define USART_TX_BLOCKING
'Fill a string with a message
Dim TestData As String
TestData = "The cat sat on the mat"
'Extract "cat". The c is at position 5, and 3 letters are needed
HSerPrint "The animal is a "
HSerPrint Mid(TestData, 5, 3)
'Extract the action. "sat" starts at position 9.
HSerPrint "The animal "
HSerPrint Mid(TestData, 9)
HSerPrintCRLF