文字列, 文字数の取得
String, Get Number of Characters
テキストの文字数を取得します。連続する空白(タブや全角空白も含む)は全体で1文字とカウントされます。改行コードをカウントしない文字数、改行と空白をカウントしない文字数も取得可能です。
Configs for this Auto Step
- conf_StrA
- A: 文字列をセットしてください *#{EL}
- conf_DataIdB
- B: 文字数が格納される数値型データを選択してください (更新)
- conf_DataIdC
- C: 改行コードを無視した文字数が格納される数値型データを選択してください (更新)
- conf_DataIdD
- D: 改行と空白を無視した文字数が格納される数値型データを選択してください (更新)
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
- String-Get-Number-of-Characters-2023.xml
- 2023-10-12 (C) Questetra, Inc. (MIT License)
(アドオン自動工程のインストールは Professional editionでのみ可能です)
Notes
- 連続する空白(タブや全角空白も含む)は全体で1文字とカウントされます。
- 改行コードを文字数にカウントしたくない場合はCを使用してください。
- 改行コードと空白を文字数にカウントしたくない場合はDを使用してください。
Capture

