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.
LOGFILE := "C:\\cookies.txt"; //path to file
sLog : string;
sResult : string;
nSize : number;
hFile : number;
hCol : string;
nCol : number;
TmyTrans1 : 1;
// Open and read in everything from cookies.txt into the variable sLog
FRead(hFile, sLog, nSize);
//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);