Rpbasic-52 programming guide – Remote Processing BASIC 52 User Manual
Page 124

RPBASIC-52 PROGRAMMING GUIDE
2-105
Syntax:
A = STR(7,$( put),$(get),position,len gth)
Description:
Extracts a portion of a string from $(get) and transfers it over to $(put). The actual num ber of characters
mov ed is re turned . position starts at 1. When position is 0, no characters are placed into $(put) regardless of
length . When length is 0, all characters are copied from $(get) to $(put) starting at position.
Example:
10 STRING 200,20
20 $(0) = "123456.789"
30 A = STR(7,$(1),$(0),3,5)
40 PRINT $(1)
50 PRINT "Length:",A
run
3456.
Length: 5
Syntax:
A = STR(8,$( search),$(substring))
Description:
Scans $(search) for occurrence of substring. Returns position where entire substring first matches search
string. Returns 0 when substring is not in search string.
Example:
10 STRING 200,20
20 $(0) = ">05M34C3"
30 $(1) = "05M"
40 A = STR(8,$(0),$(1))
50 PRINT "Position match at:",a
run
Position match at: 2
The number '0' in $(1) matches $(0) at position 2.
Syntax:
A = STR(9,$( string1),$(string2))
Description:
Compares string1 to string2. Returns position of first m ismatch. If both strings exactly m atch, then 0 is
returned.
Example:
10 STRING 200,20
20 $(0) = ">05M34C3"
30 $(1) = ">05"
40 A = STR(9,$(0),$(1))
50 PRINT "Mismatch starting at:",a
run
Mismatch starting at: 4
Since the first three character positions matched, position 4 is returned as the longer string did not match the
shorter one.
String functions 8 and 9 are useful in RS-485 network communication. In the above example, ">05" could be
the RPC-320's address. Knowing the mismatch starts at position 4, the address can be assumed correct. If the
misma tch started soone r, a smaller num ber is returned. Hen ce, the mess age was n ot intended for this
particular card and the entire message can be flushed.