Multiline String; Delete Header Lines

Multiline String; Delete Header Lines

Deletes the header lines of a multiline string, like CSV text or TSV text. Note that blank characters at the end or beginning of string data are deleted in advance. If singleline text, an empty string will be returned.

2019-07-20 (C) Questetra, Inc. (MIT License)
https://support.questetra.com/addons/multiline-string-delete-header-lines/

Configs
  • A: Select STRING DATA for Multiline Text *
  • B: Set Number of Header Lines to Delete (e.g. “1”) *
  • C: Select STRING DATA for Header-Deleted Text (update) *
Script
// (c) 2019, Questetra, Inc. (the MIT License)

//////// START "main()" ////////
main();
function main(){ 


//// == Config Retrieving / 工程コンフィグの参照 ==
const dataIdA = configs.get( "conf_DataIdA" ) + ""; // config required
const delNum  = configs.get( "conf_DelNum" )  + ""; // config required
const dataIdC = configs.get( "conf_DataIdC" ) + ""; // config required
const intDelNum  = parseInt( delNum );
// Design-time Config Format Check
if ( isNaN( intDelNum )){
  throw new Error( "\n AutomatedTask UnexpectedConfigError:" +
                   " Config DelNum is not an integer \n" );
}


//// == Data Retrieving / ワークフローデータの参照 ==
// Run-time Data Format Check
if( engine.findDataByNumber( dataIdA ) === null ){
  throw new Error( "\n AutomatedTask UnexpectedStringError:" +
                   " String {A} is null \n" );
}
const inputText = (engine.findDataByNumber( dataIdA ) + "").trim();
if( inputText === "" ){
  throw new Error( "\n AutomatedTask UnexpectedStringError:" +
                   " String {A} is empty \n" );
}


//// == Calculating / 演算 ==
let   outputText = "";
const arrInputText = inputText.split("\n");
engine.log( " AutomatedTask MultilineString:" + 
            " String {A}, number of lines " + arrInputText.length );
if( arrInputText.length < intDelNum ){
  engine.log( " AutomatedTask StringWarning:" +
    " String {A}, number of lines is smaller than DelNum \n" );
}else{
  for (let i = intDelNum; i < arrInputText.length; i++){
    outputText += arrInputText[i];
    if( i !== arrInputText.length - 1 ){
      outputText += "\n";
    }
  }
}


//// == Data Updating / ワークフローデータへの代入 ==
engine.setDataByNumber( dataIdC, outputText );


} //////// END "main()" ////////

Download

Capture

See also

2 thoughts on “Multiline String; Delete Header Lines”

  1. Pingback: Delete Rows of Tsv – Questetra Support

  2. Pingback: Multiline String; Delete Footer Lines – Questetra Support

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: