Multiline String, Get Range Lines
Extracts the specified range of rows. The range is specified by Begin Index and End Index. The index is zero-based and the index on the first row is zero. Note that the row specified by the End Index is not included in the range.
Configs
  • A1: Set Original Text *#{EL}
  • B1: Set BeginIndex (eg “0” “2” “-5” ) *#{EL}
  • B2: Set EndIndex (eg “2” “-5” “” )#{EL}
  • C1: Select STRING DATA that stores Extracted Text (update) *
Script (click to open)
// GraalJS Script (engine type: 2)

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

//// == Config Retrieving / 工程コンフィグの参照 ==
const strInput         = configs.get( "StrConfA1" );          /// REQUIRED //////////////
  if( strInput       === "" ){
    throw new Error( "\n AutomatedTask ConfigError:" +
                     " Config {A1: Text} is empty \n" );
  }
const strBeginIndex    = configs.get( "StrConfB1" );          /// REQUIRED //////////////
  if( strBeginIndex  === "" ){
    throw new Error( "\n AutomatedTask ConfigError:" +
                     " Config {B1: BeginIndex} is empty \n" );
  }
  const numBeginIndex  = parseInt( strBeginIndex, 10 );
  if( isNaN( numBeginIndex ) ){
    throw new Error( "\n AutomatedTask ConfigError:" +
                     " Config {B1: BeginIndex} must be an integer \n" );
  }
const strEndIndex      = configs.get( "StrConfB2" );          // NotRequired ////////////
  const numEndIndex    = parseInt( strEndIndex, 10 );
  if( strEndIndex    !== "" ){
    if( isNaN( numBeginIndex ) ){
      throw new Error( "\n AutomatedTask ConfigError:" +
                       " Config {B2: EndIndex} must be an integer or empty \n" );
    }
  }
const strPocketOutput  = configs.getObject( "SelectConfC1" ); /// REQUIRED //////////////


//// == Data Retrieving / ワークフローデータの参照 ==
// (Nothing. Retrieved via Expression Language in Config Retrieving)


//// == Calculating / 演算 ==
const arrInput = strInput.split("\n");
let arrOutput;

/// OutputLog and Extract
if( strEndIndex    === "" ){
  engine.log( " AutomatedTask RuntimeLog:" +
              " Range: from " + numBeginIndex + " to (end)" );
  arrOutput  = arrInput.slice( numBeginIndex );
}else{
  engine.log( " AutomatedTask RuntimeLog:" +
              " Range: from " + numBeginIndex + " to " + numEndIndex );
  arrOutput  = arrInput.slice( numBeginIndex, numEndIndex );
}

let strOutput = arrOutput.join("\n");

//// == Data Updating / ワークフローデータへの代入 ==
engine.setData( strPocketOutput, strOutput );


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

/*
Notes:
- When the process reaches this automated task, the Text in the string data is automatically processed.
    - TSV data, Access log, Email body, etc.
    - {Number of lines} = {Number of line breaks} + 1
- The range specified by the start line (Begin Index) and end line (End Index) is extracted.
    - Index starts at zero. The Index on the first line is "0". (10-line text: 0,1,2,3,4,5,6,7,8,9)
        - If a negative value for Index, interpreted as the value subtracted from the number of lines.
        - If "-1" is specified in 10 lines of text, it is the same as if "9" is specified.
    - End Index is optional. If omitted, the entire part will be extracted.
        - Even if End Index is specified to exceed the Index of the last row, the end will be extracted.
    - A case where an empty string is returned.
        - {Begin Index} >= {End Index}
        - {Begin Index} > (Index of the last line)
    - Example of range specification
        - Extract the first 5 lines (0,1,2,3,4,5,,, to 0,1,2,3,4):
            - {Begin Index}: `0`
            - {End Index}: `5`
        - Extract only the 3rd line (0,1,2,3,4,5,,, to 2):
            - {Begin Index}: `2`
            - {End Index}: `3`
        - Delete one first line (header row) (0,1,2,3,,,N to 1,2,3,,,N):
            - {Begin Index}: `1`
            - {End Index}: (empty)
        - Delete one last line (footer row) (0,1,2,,,N-1,N to 0,1,2,,,N-1):
            - {Begin Index}: `0`
            - {End Index}: `-1`

APPENDIX:
- The range specification is the same as the JavaScript `slice ()` method.
    - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice
    - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/slice
- 10-line text:0,1,2,3,4,5,6,7,8,9
    - {Begin Index}: `-10`
        - Output Line: 0,1,2,3,4,5,6,7,8,9
    - {Begin Index}: `5`, {End Index}: `20`
        - Output Line: 5,6,7,8,9
- When setting an index by referring to numeric, set an EL expression using arithmetic operations.
    - Extract only (N+1) line; (Index N)
            - {Begin Index}: `#{#q_numN}`
            - {End Index}: `#{#q_numN + 1}`


Notes-ja:
- 案件が自動処理工程に到達した際、文字列型データに保存されているTextが自動的に加工されます。
    - TSVデータ、アクセスログ、メール本文など
    - {行の数} = {改行の数} + 1
- 開始行(Begin Index)と終了行(End Index)で指定された範囲が抽出されます。
    - Index はゼロ始まりです。1行目の Index は "0" です。(10行テキストの場合:0,1,2,3,4,5,6,7,8,9)
        - Index に負の値が指定された場合、テキストの全行数から減算された値と解釈されます。
        - 10行のテキストで "-1" が指定された場合は "9" が指定された場合と同じ処理になります。
    - End Index は省略可能です。省略した場合は末尾までが抽出されます。
        - End Index に最終行の Index を超える値が指定された場合も、末尾までが抽出されます。
    - 空文字列が返されるケース。
        - {Begin Index} >= {End Index}
        - {Begin Index} > (最終行のIndex)
    - 範囲指定の例
        - 先頭の5行を抽出 (0,1,2,3,4,5… ⇒ 0,1,2,3,4):
            - {Begin Index}: `0`
            - {End Index}: `5`
        - 3行目だけを抽出 (0,1,2,3,4,5… ⇒ 2):
            - {Begin Index}: `2`
            - {End Index}: `3`
        - 先頭行(ヘッダ行)を1行削除 (0,1,2,3,…,N ⇒ 1,2,3,…,N):
            - {Begin Index}: `1`
            - {End Index}: `(empty)`
        - 最終行(フッタ行)を1行削除 (0,1,2,…,N-1,N ⇒ 0,1,2,…,N-1):
            - {Begin Index}: `0`
            - {End Index}: `-1`

APPENDIX-ja:
- 範囲の指定方法は、JavaScript `slice()` メソッドと同様です。
    - https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/Array/slice
    - https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/String/slice
- 10行テキストの場合:0,1,2,3,4,5,6,7,8,9
    - {Begin Index}: `-10`
        - Output Line: 0,1,2,3,4,5,6,7,8,9
    - {Begin Index}: `5`, {End Index}: `20`
        - Output Line: 5,6,7,8,9
- 数値型データを参照してインデックスを設定する場合、四則演算を使ったEL式設定が便利です。
    - N+1行目 (Index N) だけを抽出
            - {Begin Index}: `#{#q_numN}`
            - {End Index}: `#{#q_numN + 1}`
*/

Download

The Add-on import feature is available with Professional edition.
Freely modifiable JavaScript (ECMAScript) code. No warranty of any kind.

Notes

  • When the process reaches this automated task, the Text in the string data is automatically processed.
    • TSV data, Access log, Email body, etc.
    • {Number of lines} = {Number of line breaks} + 1
  • The range specified by the start line (Begin Index) and end line (End Index) is extracted.
    • Index starts at zero. The Index on the first line is “0”. (10-line text: 0,1,2,3,4,5,6,7,8,9)
      • If there is a negative value for Index, it will be interpreted as a subtraction from the number of lines.
      • If “-1” is specified in 10 lines of text, it is the same as if “9” is specified.
    • End Index is optional. If omitted, the entire part will be extracted.
      • Even if End Index is specified to exceed the Index of the last row, the end will be extracted.
    • A case where an empty string is returned.
      • {Begin Index} >= {End Index}
      • {Begin Index} > (Index of the last line)
    • Example of range specification
      • Extract the first 5 lines (0,1,2,3,4,5,,, to 0,1,2,3,4):
        • {Begin Index}: 0
        • {End Index}: 5
      • Extract only the 3rd line (0,1,2,3,4,5,,, to 2):
        • {Begin Index}: 2
        • {End Index}: 3
      • Delete one first line (header row) (0,1,2,3,,,N to 1,2,3,,,N):
        • {Begin Index}: 1
        • {End Index}: (empty)
      • Delete one last line (footer row) (0,1,2,,,N-1,N to 0,1,2,,,N-1):
        • {Begin Index}: 0
        • {End Index}: -1

Capture

Extracts the specified range of rows. The range is specified by Begin Index and End Index. The index is zero-based and the index on the first row is zero. Note that the row specified by the End Index is not included in the range.
Extracts the specified range of rows. The range is specified by Begin Index and End Index. The index is zero-based and the index on the first row is zero. Note that the row specified by the End Index is not included in the range.

Appendix

See also

3 thoughts on “Multiline String, Get Range Lines”

  1. Pingback: Multiline String; Delete Header Lines – Questetra Support

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

  3. Pingback: Multiline String, Get Specific Line – Questetra Support

Leave a Reply

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

%d bloggers like this: