home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Simtel MSDOS 1992 September
/
Simtel20_Sept92.cdr
/
msdos
/
turbopas
/
spoc88.arc
/
PMATCH.ARC
/
CSZ.SC
Wrap
Text File
|
1988-07-11
|
2KB
|
77 lines
; SCRIPT: CSZ.SC
; AUTHOR: Bill Cusano (516) 293-6846
; FUNCTION: Demonstrate using MATCH to parse a string
PROC CSZSplit(CSZ)
PRIVATE x4,x5
; The IF statement below tests whether the string in CSZ
; matches a given pattern. The MATCH function performs
; this test, and if the test passes, variables City and
; State are assigned the values of their corresponding
; patterns within the string. The double dot (..) pattern
; used here accepts any number of characters or numbers in
; the position.
IF MATCH(CSZ,".., ..",City,State) THEN
; The WHILE command below tests, in each pass through
; the loop, that the string value of the variable State
; matches the quoted pattern. Here, if the string
; contains a leading space, the loop continues. The
; MATCH function performs a logical test for a match
; and, upon a match, it fills the variable x4 with all
; characters to the right of the leading space.
WHILE MATCH(State," ..",x4)
; Each pass through the loop causes the variable
; State to be reassigned to the value of x4. Thus
; the string loses its leading blank space.
State = x4
ENDWHILE
; The WHILE loop above would only be run if there
; are leading spaces in the string. If it does
; not run, we need to assign the value of State to
; the variable x4, which is tested below.
x4 = State
; Here, we're using MATCH again to separate out the
; State and ZIP data from the remains of the string
; once City has been removed.
IF MATCH(x4,".. ..",State,Zip) THEN
; This WHILE statement removes leading spaces from
; Zip:
WHILE MATCH(Zip," ..",x5)
Zip = x5
ENDWHILE
ENDIF
ENDIF
ENDPROC
; Below is a test program for procedure CSZSplit:
City = ""
State = ""
Zip = ""
@ 2,4 ? "Enter String: " ; Enter a string to split
ACCEPT "A25" TO CSZ
CSZSplit(CSZ) ; Split city, state, and ZIP from CSZ
@ 6,4 ?? City ; Show the three fields split from string CSZ
@ 7,4 ?? State
@ 8,4 ?? Zip
sleep 3000