String, Batch Replace Halfwidth Numbers with Fullwidth Numbers

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” will be replaced. Symbols and letters will NOT be replaced. You can check the number of replacements in the log.
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 (click to open)

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

2021-07-07 (C) Questetra, Inc. (MIT License)
https://support.questetra.com/addons/string-batch-replace-halfwidth-numbers-with-fullwidth-numbers-2021/
The Addon-import feature is available with Professional edition.

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

Capture

See also

Zip Code Japan

2 thoughts on “String, Batch Replace Halfwidth Numbers with Fullwidth Numbers”

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

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

Comments are closed.

Discover more from Questetra Support

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

Continue reading

Scroll to Top