String, Get Number of Characters

String, Get Number of Characters

文字列, 文字数の取得

Gets the number of characters in the text. Consecutive blanks (including tabs and double-byte spaces) are counted as one character. The number of characters that do not count linefeed codes and blanks can also be obtained.

Auto Step icon
Configs for this Auto Step
conf_StrA
A: Set String *#{EL}
conf_DataIdB
B: Select NUMERIC DATA for Number of Characters (update)
conf_DataIdC
C: Select NUMERIC for #Characters ignoring LF (update)
conf_DataIdD
D: Select NUMERIC for #Characters ignoring LF and Space (update)
Script (click to open)

// GraalJS Script (engine type: 3)
// 
// Notes:
// Counts consecutive spaces (including tabs and double-byte spaces) as one character.
// Use C if you do not want to count linefeed codes as characters.
// Use D if you do not want to count linefeed codes and spaces as characters.
// 
// Notes (ja):
// 連続する空白(タブや全角空白も含む)は全体で1文字とカウントされます。
// 改行コードを文字数にカウントしたくない場合はCを使用してください。
// 改行コードと空白を文字数にカウントしたくない場合はDを使用してください。


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

//// == Config Retrieving / 工程コンフィグの参照 ==
const strA    = configs.get( "conf_StrA" )    + ""; // required
const dataIdB = configs.get( "conf_DataIdB" ) + ""; // not required
const dataIdC = configs.get( "conf_DataIdC" ) + ""; // not required
const dataIdD = configs.get( "conf_DataIdD" ) + ""; // not required
if( strA === "" ){
  engine.log( " AutomatedTask StringWarning:" +
              " Config {A} is empty" );
}


//// == Data Retrieving / ワークフローデータの参照 ==
// (nothing)


//// == Calculating / 演算 ==
const strB = strA.replace(/\s+/g," ");
const strC = strA.replace(/\r|\n/g, "").replace(/\s+/g," ");
const strD = strA.replace(/\s/g,"");
// Note) Tab and double byte space are included in "\s" (UTF-8) 
// including space, tab, form feed, line feed, and other Unicode spaces.

const numB = strB.length;
const numC = strC.length;
const numD = strD.length;


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


} //////// 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

  • Counts consecutive spaces (including tabs and double-byte spaces) as one character.
  • Use C if you do not want to count linefeed codes as characters.
  • Use D if you do not want to count linefeed codes and spaces as characters.

Capture

See Also

%d