TSV 文字列; 特定列に接尾辞

TSV 文字列; 特定列に接尾辞
TSV 文字列; 特定列に接尾辞 (TSV String; Add Suffix to Column)
指定したカラムの全データに接尾辞Strを結合し、新しいTSV文字列を生成します。結合文字列は各行末に要素追加されます。敬称や通貨単位の追加などでご利用いただけます。TSV文字列の末尾先頭にある空白文字や改行文字は事前に削除します。
Configs
  • A: TSV テキストが格納されている文字列型データ項目を選択してください *
  • B: 接尾辞を結合するカラムIDをセットしてください (例 “0”) *
  • C: 接尾辞をセットしてください (例 ” Mbps”, ” 様”, “百万円”)#{EL}
  • D: 結合前に文字列末尾を削除する場合は削除する文字数を負の数でセットしてください (例 “-6”) *
  • E: 新しいTSVテキストが格納される文字列型データ項目を選択してください(更新) *
Script (click to open)
// GraalJS Script (engine type: 2)
// (c) 2021, Questetra, Inc. (the MIT License)

/*
=input tsv=
A1	B1	C1	10000
A2	B1	C1	10800
=Column ID=
3
=Suffix=
Mbps
=EndIndex=
-3
=output tsv=
A1	B1	C1	10000	10Mbps
A2	B1	C1	10800	10Mbps
*/

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


//// == Config Retrieving / 工程コンフィグの参照 ==
const dataIdA = configs.get( "conf_DataIdA" ) + ""; // config required
const columnB = configs.get( "conf_ColumnB" ) + ""; // config required (int)
const suffixC = configs.get( "conf_SuffixC" ) + ""; // config el-enabled
const endIndex = configs.get( "conf_EndIndex" ) + ""; // config required (int)
const dataIdE = configs.get( "conf_DataIdE" ) + ""; // config required
// 'java.lang.String' to javascript primitive 'string' by ""

engine.log( " AutomatedTask Config: ID of Numeric Column: " + columnB );
engine.log( " AutomatedTask Config: Suffix: " + suffixC );
engine.log( " AutomatedTask Config: End Index: " + endIndex );

// Design-time Config Format Check
const intColumnB  = parseInt( columnB );
if( isNaN( intColumnB )){
  throw new Error( "\n AutomatedTask ConfigError:" +
                   " Config {ID of Numeric Column} is not an integer \n" );
}
const intEndIndex = parseInt( endIndex );
if( isNaN( intEndIndex )){
  throw new Error( "\n AutomatedTask ConfigError:" +
                   " Config {End Index} is not an integer \n" );
}
if( suffixC === "" ){
  engine.log( " AutomatedTask ConfigWarning:" +
              " Config {Suffix} is empty" );
}
if( suffixC.match(/\t/) !== null ){
  throw new Error( "\n AutomatedTask ConfigError or UnexpectedStringError:" +
                   " Config {Suffix}, Tab characters are not allowed. \n" );
}


//// == Data Retrieving / ワークフローデータの参照 ==
// Run-time Data Format Check
if( engine.findDataByNumber( dataIdA ) === null ){
  throw new Error( "\n AutomatedTask UnexpectedStringError:" +
                   " String {A} as TSV is null \n" );
}
const inputText = (engine.findDataByNumber( dataIdA ) + "").trim();
if( inputText === "" ){
  throw new Error( "\n AutomatedTask UnexpectedStringError:" +
                   " String {A} as TSV is empty \n" );
}


//// == Calculating / 演算 ==
let   outputText = "";
const arrInputText = inputText.split("\n");
engine.log( " AutomatedTask MultilineString:" + 
            " String {A} as TSV, number of lines " + arrInputText.length );

for( let i = 0; i < arrInputText.length; i++ ){
  let arrCellValues = arrInputText[i].split("\t");
  let strValueB = arrCellValues[ intColumnB ];
  let newValue  = "";
  if( intEndIndex === 0 ){
    newValue  = strValueB + suffixC;
  }else{
    newValue  = strValueB.slice( 0, intEndIndex ) + suffixC;
  }
  outputText += arrInputText[i] + "\t" + newValue;
  if( i !== arrInputText.length - 1 ){
    outputText += "\n";
  }
}


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


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

Download

2021-07-15 (C) Questetra, Inc. (MIT License)
https://support.questetra.com/ja/addons/tsv-string-add-prefix-to-column-2021/
Addonファイルのインポートは Professional でのみご利用いただけます

Notes

  1. EndIndex D に正の数を指定した場合は、抽出範囲の終了位置インデックス(N文字目まで抽出)とみなします。

Capture

See also

https://support.questetra.com/ja/addons/tsv-string-add-prefix-to-column-2021/

Questetra Supportをもっと見る

今すぐ購読し、続きを読んで、すべてのアーカイブにアクセスしましょう。

続きを読む

上部へスクロール