> ## Documentation Index
> Fetch the complete documentation index at: https://docs.kasoftware.com/llms.txt
> Use this file to discover all available pages before exploring further.

# 格式化器

> ArcScript 值格式化器概觀，用於在指令碼和運算式設定中修改和格式化資料。

export const siteNameShort = "知行之橋";

格式化器支援在指令碼或運算式設定中修改或格式化值，並透過接受輸入和生成輸出來執行。輸入會以專案屬性的形式傳遞給格式化器，也可以作為[函式](./function-formatters)傳遞。

本節中定義的格式化器根據其接受的輸入型別進行分類：

* [字串](./string-formatters)
* [陣列](./array-string-formatters)
* [日期](./date-formatters)
* [數字](./number-formatters)
* [檔案](./file-formatters)

函式雖然與格式化器的使用方式相同，但會生成輸出且不需要顯式輸入。有關詳細資訊，請參閱[函式](./function-formatters)。

## 格式化器基礎知識

屬性（變數）使用豎線字元 `|` 傳遞給格式化器：

`[item.attribute | formatter(parameters)]`

其中 *formatter* 是格式化器名稱，*parameters* 是用於控制格式化器輸出的可選參數集。可以使用豎線分隔各個格式化器，從而使用多個格式化器；格式化器將從左到右求值，一個格式化器的輸出會“管道傳遞”給下一個格式化器：

`[item.attribute | formatter(parameters) | formatter(parameters) | ...]`

## 範例

* 在以下片段中，`myid` 屬性值中的任何 "\*" 字元都會替換為 "-"，生成的值會分配給 `input1.id`。

  ```xml theme={null}
  <arc:set attr="input1.id" value="[myid | replace('*', '-')]"/>
  ```

* 下面，兩個值格式化器使用管道（"|"）字串聯。在此範例中，只有 `.log` 檔案會從操作中推送。

  ```xml theme={null}
  <arc:call op="fileListDir">
    <arc:check attr="name" value="[filename | tolower | endswith('.log')]">
      <arc:push/>
    </arc:check>
  </arc:call>
  ```

* 採購訂單行專案的總成本可能需要透過將專案數量乘以每項價格來計算。

  ```xml theme={null}
  <arc:set attr="cost" value="[itemQuantity | multiply([itemPrice])]" />
  ```
