Read and Log File Contents Using Commas and New Lines as Separators
The following sample reads and logs strings from a file using commas and new line characters as separators. This sample can be used as the starting point for a parser implementation.
Note:
This script sample uses the define function, which is required for an entry point script (a script you attach to a script record and deploy). You must use the require function if you want to copy the script into the SuiteScript Debugger and test it. For more information, see SuiteScript 2.x Global Objects.
/**
* @NApiVersion 2.x
* @NScriptType bankStatementParserPlugin
*/
define(['N/file', 'N/log'], function(file, log) {
return {
parseBankStatement: function(context) {
var reader = context.input.file.getReader();
var textUntilFirstComma = reader.readUntil(',');
var next10Characters = reader.readChars(10);
var textUntilNextNewLine = reader.readUntil('\n');
var next100Characters = reader.readChars(100);
log.debug({
title: 'STATEMENT TEXT',
details: textUntilFirstComma
});
log.debug({
title: 'STATEMENT TEXT',
details: next10Characters
});
log.debug({
title: 'STATEMENT TEXT',
details: textUntilNextNewLine
});
log.debug({
title: 'STATEMENT TEXT',
details: next100Characters
})
}
}
});
Related Topics
- N/file Module Script Samples
- Create and Save a File to the File Cabinet
- Create a File, Set Property Values, and Save It to the File Cabinet
- Create and Save a CSV File then Reload the File and Parse Its Contents
- Read and Log Segments of a File Using a Set of Characters as Separators
- Copy a File Using Conflict Resolution
- SuiteScript 2.x Modules
- SuiteScript 2.x