Multiline String: Get Number of Lines

Multiline String: Get Number of Lines

translate 複数行文字列: 行数の取得

Gets the number of lines of text. The number of lines that do not count the trailing newline codes can also be stored.

Auto Step icon
Configs for this Auto Step
conf_DataIdA
A: Select STRING DATA for Multiline Text *
conf_DataIdB
B: Select NUMERIC DATA for Number of Lines (update)
conf_DataIdC
C: Select NUMERIC DATA for Number of Lines Trimmed (update)
Script (click to open)
// Script for 'engine type: 3' ("GraalJS standard mode")
// cf 'engine type: 2' renamed from "GraalJS" to "GraalJS Nashorn compatible mode" (at 20230526)


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


//// == Config Retrieving / 工程コンフィグの参照 ==
const dataIdA = configs.get( "conf_DataIdA" ) + ""; // config required
const dataIdB = configs.get( "conf_DataIdB" ) + ""; // config not required
const dataIdC = configs.get( "conf_DataIdC" ) + ""; // config not required


//// == 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 ) + "";
const inputText2 = inputText.replace(/[\n]*$/, "");


//// == Calculating / 演算 ==
const arrInputText = inputText.split("\n");
engine.log( " AutomatedTask MultilineString:" + 
            " String {A}, number of lines " + arrInputText.length );
const arrInputText2 = inputText2.split("\n");
engine.log( " AutomatedTask MultilineString:" + 
            " String {A}, number of lines trimmed " + arrInputText2.length );


//// == Data Updating / ワークフローデータへの代入 ==
if ( dataIdB !== "" ){ 
  engine.setDataByNumber( dataIdB, new java.math.BigDecimal( arrInputText.length ) );
}
if ( dataIdC !== "" ){ 
  engine.setDataByNumber( dataIdC, new java.math.BigDecimal( arrInputText2.length ) );
}


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

Download

warning Freely modifiable JavaScript (ECMAScript) code. No warranty of any kind.
(Installing Addon Auto-Steps are available only on the Professional edition.)

Notes

  • Gets the number of lines of text

Capture

See Also

Leave a Reply

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

%d bloggers like this: