String: Replace All

String: Replace All

translate 文字列: 全置換

Replaces all the search strings by the replacement string. All matches are case sensitive. For example, it is possible to completely replace the string “XXXX-XX-XX” in the template text with “2020-05-11”.

Auto Step icon
Configs for this Auto Step
conf_StrA
A: Set String *#{EL}
conf_StrSub
B: Set Search String *#{EL}
conf_StrNew
C: Set Replacement String *#{EL}
conf_DataIdD
D: Select STRING DATA for Replaced String (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 strA    = configs.get( "conf_StrA" )    + ""; // required
const strSub  = configs.get( "conf_StrSub" )  + ""; // required
const strNew  = configs.get( "conf_StrNew" )  + ""; // required
const dataIdD = configs.get( "conf_DataIdD" ) + ""; // required
engine.log( " AutomatedTask Search: " + strSub );
engine.log( " AutomatedTask Replacement " + strNew );


//// == Data Retrieving / ワークフローデータの参照 ==
// (nothing, except Expression Language config)


//// == Calculating / 演算 ==
// Escaping for a literal string search
// For a wider range of values, comment out and use Patterns with special characters
let myMatch = new RegExp( strSub
                          .replace(/[.*+?^=!:${}()|[\]\/\\]/g, '\\$&')
                          , 'g' ); // global match
let strOutput = strA.replace( myMatch, strNew );


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

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

// Notes:
- Regular expressions cannot be used in the search string.
- Can also replace strings that include line breaks and tabs.

// Notes (ja):
- 検索文字列の設定に正規表現は利用できません。
- 改行コードやタブコードを含む文字列も置換可能です。

Download

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

Notes

  • Regular expressions cannot be used in the search string.
  • Can also replace strings that include line breaks and tabs.

Capture

See Also

Discover more from Questetra Support

Subscribe now to keep reading and get access to the full archive.

Continue reading