Call 64: find a string in a string – Rockwell Automation 1771-DB BASIC MODULE User Manual

Page 253

Advertising
background image

Chapter
Call Routines 0–68

12

12 -63

Use this routine to find a string within a string. It locates the first
occurrence (position) of this string. This routine is similar to the ANSI
BASIC INSTR$(findstr$,str$). (Example: L=INSTR$($(1),$(2))

Input and Output Arguments

This routine has two input arguments and one output argument. The first
input is the string you want to find. The second input is the string you
want to search for a match. The output argument is the location of the
matched string. If the number is not zero then a match was located at the
position the value of the return argument indicates.

Syntax

PUSH

string number of string to be found

PUSH

base string number

CALL 64

POP

return value

Example

>10 REM SAMPLE FIND STRING IN STRING ROUTINE

>20 STRING 1000,20

>30 $(1)=“456”

>40 $(2)=“12345678”

>50 PUSH 1 :REM STRING NUMBER OF STRING TO BE FOUND

>60 PUSH 2 :REM BASE STRING NUMBER

>70 CALL 64 :REM GET LOCATION OF FIRST CHARACTER

>80 POP L

>90 IF L=0 THEN PRINT “NOT FOUND”

>100 IF L>0 THEN PRINT “FOUND AT LOCATION ”,L

>110 END

>RUN

FOUND AT LOCATION 4

READY

CALL 64: Find a String
in a String

Advertising