> ## 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 值格式化器概述，用于在脚本和表达式设置中修改和格式化数据。

格式化器支持在脚本或表达式设置中修改或格式化值，并通过接受输入和生成输出来运行。输入会以项目属性的形式传递给格式化器，也可以作为[函数](https://docs.kasoftware.com/26.4/self-hosted/zh/scripting/value-formatters/function-formatters.md)传递。

本节中定义的格式化器根据其接受的输入类型进行分类：

* [字符串](https://docs.kasoftware.com/26.4/self-hosted/zh/scripting/value-formatters/string-formatters.md)
* [数组](https://docs.kasoftware.com/26.4/self-hosted/zh/scripting/value-formatters/array-string-formatters.md)
* [日期](https://docs.kasoftware.com/26.4/self-hosted/zh/scripting/value-formatters/date-formatters.md)
* [数字](https://docs.kasoftware.com/26.4/self-hosted/zh/scripting/value-formatters/number-formatters.md)
* [文件](https://docs.kasoftware.com/26.4/self-hosted/zh/scripting/value-formatters/file-formatters.md)

函数虽然与格式化器的使用方式相同，但会生成输出且不需要显式输入。有关详细信息，请参阅[函数](https://docs.kasoftware.com/26.4/self-hosted/zh/scripting/value-formatters/function-formatters.md)。

## 格式化器基础知识

属性（变量）使用竖线字符 `|` 传递给格式化器：

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


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.