A NEW TODAY IS DAWNING!

Tutorial: New Commands in Version 8.01


Introduction

The following provides details of the new commands introduced in BuildProfessional Version 8.01.

STRING *FIND / *REPLACETEXT *NEXT ... *MATCH


STRING *FIND / *REPLACE
 

Syntax

STRING *FIND findref sourceref [*START= start-dataref] [*LENGTH= length-dataref] [*NOCASE]

STRING *REPLACE findref replaceref sourceref destref [*START= start-dataref] [*LENGTH= length-dataref] [*NOCASE]

Where:

findref is the data reference to find.

sourceref is the data reference to search.

start-dataref is an optional character position to start the search.

length-dataref is an optional length of the sourceref to search (starting at start-dataref).


Description


Conditionally find and replace characters in a string. Used for complex situations where string processing is based on one or many conditions. The typical operation is to find and then replace portions of a string in a loop. The flexibility of the command allows the developer to "back-up" or "skip-forward" depending on the situation.


Operation Summary


*FIND. Finds the starting position of a string in a character string. The position is returned in *PASS. The starting position is such that is can be used in a subsequent STRING *REPLACE command.

*REPLACE. Finds and replaces one or several characters in a string. The position of start of the replace is returned in *PASS. Use in a loop to perform multiple replaces.

Note. As an alternative, the REPLACE command will do an unconditional replace of all instances of string.

Example:

NOTE Conditional replace of all instances of “x” with “abc”

L-Xvalue = "sample x x x test"
L-Xcount = 0
FOREVER
NOTE --- Find x's:
STRING *FIND "x" L-Xvalue *START= L-Xcount
IF *PASS = 0 THEN BREAK

L-Xcount = *PASS
*ERROR = "3Replace 'x' at position " *TRIM(L-Xcount) " in the string: " L-Xvalue
ERROR *ERROR
IF *ERRSTAT <> 2 THEN
NOTE --- Do a single replace:
STRING *REPLACE "x" "abc" L-Xvalue L-Xvalue *START= L-Xcount
ENDIF

NOTE --- Move our position forward:
L-Xcount += 1
ENDFOR

NOTE --- Conclude:
*ERROR = "3The resulting string is: " L-Xvalue
ERROR *ERROR


TEXT *NEXT ... *MATCH


Syntax


TEXT *NEXT filehandleref *MATCH= matchref destref

Where:

filehandleref is the data reference containing the file handle (from TEXT *OPEN).

matchref is a string containing characters and wildcards (* and ?) to look for.

destref is the destination data reference for lines read that match the wildcard.
 

Description

Read lines from a file that match one or several wild cards.


Operation Summary


*MATCH. Finds the lines matching a wildcard. For example all lines matching "*Error*".


Example:


NOTE Write all lines containing "Error" to output.txt:
TEXT *OPEN "myfile" "c:/myfile.txt"

FOREVER
TEXT *NEXT "myfile" *MATCH= "*Error* *P01
IF *IOSTATUS <> 0 THEN BREAK
TEXT *RAW *FILE= "output.txt" *P01
ENDFOR

TEXT *CLOSE "myfile"

NOTE Start reading a file at "<body>":
TEXT *OPEN "page" "webpage.htm"
TEXT *NEXT "page" *MATCH= "*<body>*" L-string

FOREVER
TEXT *NEXT "page" L-string
IF *IOSTATUS <> 0 THEN BREAK
ENDFOR
...