This page documents some procedures that can be use to
- Retrieve strings from a stream file
- Replace strings in a stream file
- Extract a string from a stream file
Such procedures are exported from service program WRKSTMF/WRKSTMF.
Procedure prototypes are available in WRKSTMF/QRPGLESRC, member XXXPROTO.
|
1. Procedure RtvStmfStg() Retrieve Stream File String
This procedure returns an array containing all the starting positions of a given string in a given stream file.
Input variables:
- The qualified name of a stream file
- The character string to be retrieved
Variable returned:
- An array of 1,000 elements. Each element documents a position of that string in the stream file. The first element containing zero ends the list.
Procedure protocol:
D RtvStmfStg pr 4000
D stmf 256
D schString 100 varying |
|
|
|
Example of using it:
D stmf s 256
D schString s 100 varying
D fndDS ds
D fndArray 10i 0 dim(1000)
/free
stmf='/wrkstmf/samples/Puss_in_Boots.txt';
schString=' cat ';
fndDS=RtvStmFStg(stmf:schString);
|
|
|
Program WRKSTMF/TESTRTVSTG (source in WRKSTMF/QRPGLESRC) provides an executable example of retrieving
string ' cat ' from stream file /wrkstmf/samples/Puss_in_Boots.txt.
Three entries are found, and their positions are documented in array fndArray.
|
2. Procedure RplStmfStg() Replace Stream File String
This procedure copies a given stream file to another stream file. During the copy process, it replaces the instances of a given string with instances of another string.
Input variables:
- The qualified name of the stream file containing the strings to be replaced
- The qualified name of a stream file that will contain a copy of the previous stream file with the appropriate strings being replaced.
- The character string to be retrieved
- The replacing character string
- An array of 1,000 elements. Each element documents a position of that character string in the stream file. The first element containing zero ends the list.
Procedure protocol:
D RplStmfStg pr
D stmf 256
D stmf2 256
D schString 100 varying
D rplString 100 varying
D fndDS 4000 |
|
|
|
Example of using it:
D stmf s 256
D schString s 100 varying
D fndDS ds
D fndArray 10i 0 dim(1000)
D stmf2 s 256
D rplString s 100 varying
/free
stmf='/wrkstmf/samples/Puss_in_Boots.txt';
schString=' cat ';
stmf2='/tmp/Goose_in_boots.txt';
rplString=' goose ';
RplStmfStg(stmf:stmf2:schString:rplString:FndDS);
|
|
|
Program WRKSTMF/TESTRPLSTG (source in WRKSTMF/QRPGLESRC) provides an executable example of copying
stream file /wrkstmf/samples/Puss_in_Boots.txt to
stream file /tmp/Goose_in_Boots.txt
while replacing string ' cat ' with string ' goose '.
|
3. Procedure ExtStmfStg() Extract Stream File String
This procedure extracts a given string from a given stream file and copies it to a new stream file.
Input variables:
- The qualified name of the stream file containing the strings to be replaced
- The qualified name of a stream file that will contain the extracted string.
- The starting position of the string to be extracted.
- The length of the string to be extracted.
Procedure protocol:
D ExtlStmfStg pr
D stmf 256
D stmf2 256
D stringPos 10i 0
D stringLen 10i 0 |
|
|
|
Example of using it:
D stmf s 256
D StringPos s 10i 0
D StringLen s 10i 0
D stmf2 s 256
/free
stmf ='/wrkstmf/samples/Puss_in_Boots.txt';
stmf2='/tmp/Chapter2.txt';
stringPos=911;
stringLen=868;
ExtStmfStg(stmf:stmf2:stringPos:stringLen);
|
|
|
Program WRKSTMF/TESEXTSTG (source in WRKSTMF/QRPGLESRC) provides an executable example of extracting a string from
stream file /wrkstmf/samples/Puss_in_Boots.txt and copying it to
stream file /tmp/Chaper2.txt.
|
|