> ## 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])]" />
  ```
