#複数行文字列: 空行の削除

#複数行文字列: 空行の削除

translate #Multiline-String: Remove Blank Lines

空行を削除します。全ての空行を削除するモードと連続する空行を1行に集約するモードがあります。

Auto Step icon
Configs for this Auto Step
StrConfA
A: テキストをセットしてください *#{EL}
BoolConfB
B: 全空行を削除 ⇔ 連続空行を1行に
SelectConfC
C: 削除後のテキストが格納される文字列型データを選択してください (更新) *
SelectConfD1
D1: テキスト行数を格納する数値型データを選択してください (更新)
Script (click to open)
// Script Example of Business Process Automation
// for 'engine type: 3' ("GraalJS standard mode")
// cf. 'engine type: 2' ("GraalJS Nashorn compatible mode") (renamed from "GraalJS" at 20230526)


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

//// == Config Retrieving / 工程コンフィグの参照 ==
const strInput       = configs.get       ( "StrConfA" );      // REQUIRED
  if( strInput     === "" ){
    throw new Error( "\n AutomatedTask ConfigError:" +
                     " Config {A: InputText} is empty \n" );
  }
const numInputLines  = strInput.split("\n").length;

const boolCombine    = configs.getObject ( "BoolConfB" );     // TOGGLE
  // https://questetra.zendesk.com/hc/ja/articles/360024574471-R2300 "Boolean object"
const strPocketC     = configs.getObject ( "SelectConfC" );   // REQUIRED
const numPocketD1    = configs.getObject ( "SelectConfD1" );  // not required



//// == Data Retrieving / ワークフローデータの参照 ==
// (nothing)



//// == Calculating / 演算 ==

let strOutput = boolCombine ?                                            // Conditional Operator
                strInput.replace(/(\r\n){3,}|\r{3,}|\n{3,}/g, '\n\n') : // true
                strInput.replace(/(\r\n){2,}|\r{2,}|\n{2,}/g, '\n') ;   // false



//// == Data Updating / ワークフローデータへの代入 ==
/// ref) Retrieving / Updating from ScriptTasks
/// https://questetra.zendesk.com/hc/en-us/articles/360024574771-R2301
/// https://questetra.zendesk.com/hc/ja/articles/360024574771-R2301

if ( strPocketC !== null ){ 
  engine.setData( strPocketC, strOutput );
}
if ( numPocketD1 !== null ){ 
  engine.setData( numPocketD1, new java.math.BigDecimal( numInputLines ) );
}

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



/*
NOTES
- The Process reaches this [Automated Step], the "Remove Blank Lines" is automatically executed.
    - Consecutive line break codes in the input text will be replaced.
- The number of lines in the input text can also be recorded.

NOTES-ja
- この[自動工程]に案件が到達すると、「空行削除」が自動実行されます。
    - Inputテキスト内にある「連続改行コード」が置換されます。
- 入力Inputテキストの行数も記録可能です。


▼Test Data for Debug:
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.

Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. 


Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.




APPENDIX
- A line containing only whitespace characters is not considered a blank line.
- 「空白文字のみの行」は空行とはみなされません。
*/

Download

warning 自由改変可能な JavaScript (ECMAScript) コードです。いかなる保証もありません。
(アドオン自動工程のインストールは Professional editionでのみ可能です)

Notes

  • この[自動工程]に案件が到達すると、「空行削除」が自動実行されます。
    • Inputテキスト内にある「連続改行コード」が置換されます。
  • 入力Inputテキストの行数も記録可能です。
  • 「空白文字のみの行」は空行とはみなされません。

Capture

See Also

上部へスクロール

Questetra Supportをもっと見る

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

続きを読む