Having problems with your account or logging in?
A lot of changes are happening in the community right now. Some may affect you. READ MORE HERE

How can I use a custom delimiter with a text file?

How can I use a custom delimiter with a text file?

If you are unable to use a RndFile or CSV file due to an issue with their pre-determined delimiter as per:

Why am I not getting the whole value when reading from a CSV or RndFile?

You may want to create a custom delimiter to use with a text file for example to read a value which contains the CSV , (comma) or RndFile ; (semi colon) delimiter. To do this the text file will need to contain a custom delimiter, in the example here we have used "start" at the beginning and "end" at the end of each value.

In the script below the value nCol can be used to specify which line or column should be read. The script and text file are attached to this resolution.



benchmark BenchmarkName
use "kernel.bdh"

const
LOGFILE := "C:\\cookies.txt"; //path to file

var
sLog : string;
sResult : string;
nSize : number;
hFile : number;
hCol : string;
nCol : number;

dcluser
user
VirtUser
transactions
TmyTrans1 : 1;

dcltrans

transaction TmyTrans1
begin
// Open and read in everything from cookies.txt into the variable sLog
FOpen(hFile, LOGFILE);
FSizeGet(hFile, nSize);
FRead(hFile, sLog, nSize);
FClose(hFile);

//Use nCol to decide which row to select and then assign that value to
the string hCol
nCol := 1;
hCol := string(nCol);

//Search for a string delimited on the left by left_boundary and on the right by right_boundary.
//Note that the space after start and before end are required as they are in the file.
//sResult receives the found substring
StrSearchDelimited(sResult, nSize, sLog, "start " + hCol + " ", 1, " end", 1, STR_SEARCH_FIRST);

Print("Value is : " + sResult);
WriteLn("Value is : " + sResult);
end TmyTrans1;

DISCLAIMER:

Some content on Community Tips & Information pages is not officially supported by Micro Focus. Please refer to our Terms of Use for more detail.
Top Contributors
Version history
Revision #:
1 of 1
Last update:
‎2013-02-15 19:12
Updated by:
 
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.