String, Batch Replace Halfwidth Numbers with Fullwidth Numbers
String, Batch Replace Halfwidth Numbers with Fullwidth Numbers

Replaces all half-width numbers with full-width numbers. Numbers from “0” to “9” are to be replaced. Symbols and letters are NOT replaced. The replacement count is output to the log.

2020-02-04 (C) Questetra, Inc. (MIT License)
https://support.questetra.com/addons/string-batch-replace-halfwidth-numbers-with-fullwidth-numbers/

Configs
  • A: Set Input String * #{EL}
  • B: Select STRING DATA for Output String (update) *
  • C: Select NUMERIC DATA for Number of Replaced Chars (update)
Script
// (c) 2020, Questetra, Inc. (the MIT License)
// Notes:
// Halfwidth Numbers (Hankaku / 半角)
// https://www.unicode.org/charts/PDF/U0000.pdf
// "0":U+0030, "1":U+0031, "2":U+0032, "3":U+0033, "4":U+0034,
// "5":U+0035, "6":U+0036, "7":U+0037, "8":U+0038, "9":U+0039
// Fullwidth Numbers (Zenkaku / 全角)
// https://www.unicode.org/charts/PDF/UFF00.pdf
// "0":U+FF10, "1":U+FF11, "2":U+FF12, "3":U+FF13, "4":U+FF14,
// "5":U+FF15, "6":U+FF16, "7":U+FF17, "8":U+FF18, "9":U+FF19

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

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

if( strInput === "" ){
  engine.log( " AutomatedTask ConfigWarning:" +
              " Config {ID String} is empty" );
}


//// == Data Retrieving / ワークフローデータの参照 ==
// Nothing (except EL-expression Config)


//// == Calculating / 演算 ==
let strForCount = strInput.replace(/[0-9]/g, "");
let strOutput = strInput.replace(/[0-9]/g, 
                                 function(s){
                                   return String.fromCharCode(s.charCodeAt(0) + 0xFEE0);
                                 });

let numReplaced = strOutput.length - strForCount.length;
engine.log( " AutomatedTask #Replaced: " + numReplaced );


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

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

Download

Capture

Replaces all half-width numbers with full-width numbers. Numbers from "0" to "9" are to be replaced. Symbols and letters are NOT replaced. The replacement count is output to the log.

Notes

  1. Halfwidth Numbers (Hankaku / 半角) https://www.unicode.org/charts/PDF/U0000.pdf
    • “0”:U+0030, “1”:U+0031, “2”:U+0032, “3”:U+0033, “4”:U+0034,
    • “5”:U+0035, “6”:U+0036, “7”:U+0037, “8”:U+0038, “9”:U+0039
  2. Fullwidth Numbers (Zenkaku / 全角) https://www.unicode.org/charts/PDF/UFF00.pdf
    • “0”:U+FF10, “1”:U+FF11, “2”:U+FF12, “3”:U+FF13, “4”:U+FF14,
    • “5”:U+FF15, “6”:U+FF16, “7”:U+FF17, “8”:U+FF18, “9”:U+FF19

See also

1 thought on “String, Batch Replace Halfwidth Numbers with Fullwidth Numbers”

  1. Pingback: String, Batch Replace Fullwidth Numbers with Halfwidth Numbers – Questetra Support

Leave a Reply

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

%d bloggers like this: