> ## 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 中转换、替换、拆分和重构字符串值的格式化器。

## concat(\[newString])

将传入格式化器的值与传给格式化器的参数拼接在一起。

* **newString**：要追加到属性的字符串。

## insert(integer\_index, string)

在指定索引处插入指定的字符串。

* **index**：原值中应插入新字符串的位置，从 0 开始计数。
* **string**：要插入到原始值中的字符串。

## regexreplace(pattern, newvalue\[, startindex])

在输入字符串中搜索 *pattern* 指定的正则表达式模式，并用 *newvalue* 替换每个出现项。

* **pattern**：要替换的正则表达式模式。
* **newvalue**：要用作替换项的值。
* **startindex**：如果提供，则搜索从字符串中的此位置开始（换句话说，格式化器会忽略 *startindex* 之前出现的 *pattern* 实例）。
* **empty\_match\_all**：如果替换正则表达式模式会返回空值，则改为返回原始字符串（默认值为 `true`）。

### 示例

```xml theme={null}
<arc:set attr="myString" value="The cost of the item is $12.98." />
<arc:set attr="decimalPattern" value="\[0-9\]+\.?\[0-9\]*" />
<arc:set attr="updatedListing" value="[myString | regexreplace([decimalPattern],'10.99')]" />
<!-- updatedListing has the value: The cost of the item is $10.99 -->
```

## remove(integer\_index\[, integer\_count])

从属性值中删除字符，从第一个参数指定的从 0 开始的索引处开始。

* **index**：开始删除字符的位置。
* **count**：可选的要删除的字符数。如果未提供，则删除从指定索引开始的所有字符。

## replace(oldvalue, newvalue\[, ishex])

在输入字符串中搜索每个 *oldvalue* 出现项，将其删除，并替换为 *newvalue*。

* **oldvalue**：要替换的原始值。
* **newvalue**：要用作替换项的值。
* **ishex**：指示 *oldvalue* 参数是否为要替换字符的十六进制表示形式（默认值为 `false`）。
* **empty\_match\_all**：如果替换 *oldvalue* 会返回空字符串，则改为返回原始值（默认值为 `true`）。

### 示例

```xml theme={null}
<arc:set attr="myString" value="I hope you have a wonderful day." />
<arc:set attr="honestString" value="[myString | replace('you', 'I')]" />
<!-- honestString holds the value: I hope I have a wonderful day. -->
<arc:set attr="anotherString" value="[myString | replace(20, '-', true)]" />
<!-- anotherString holds the value: I-hope-you-have-a-wonderful-day. -->
```

## rsplit(delimiter, integer\_index)

将属性值表示的字符串按第一个参数作为分隔符拆分为标记，并返回第二个参数指定索引处的标记。它从右侧开始计数。

* **delimiter**：用于将字符串拆分为标记的分隔符字符串。
* **index**：请求的标记索引，第一个标记的索引为 1。

## split(delimiter, indextoreturn, trimresult, removeempty)

在每次出现 *delimiter* 的位置拆分输入字符串，生成一组子字符串，然后返回给定 *index* 处的字符串。

* **indextoreturn**：如果提供，则对子字符串集合建立索引以返回其中一个子字符串（例如，将 `1` 作为 *indextoreturn* 传入会返回拆分产生的第一个子字符串）。
* **trimresult**：默认情况下，返回值会去除前导和尾随空白。将其设置为 `false` 可返回子字符串中的所有字符。
* **removeempty**：默认情况下，格式化器不会删除空元素。将其设置为 `true` 可删除空元素。

### 示例

```xml theme={null}
<arc:set attr="myName" value="Walter White" />
<arc:set attr="firstName" value="[myName | split(' ',1)]" />
<!-- firstName contains the value: Walter -->
```

## striphtml()

返回删除了所有 HTML 标记的字符串。

## substring(index\[, length])

返回输入字符串值的子字符串，从 *index* 值开始，并在 *length* 个字符后结束。如果未提供 *length*，则子字符串会持续到原始字符串的末尾。

### 示例

```xml theme={null}
<!-- parse out the characters before the first comma, combining substring() with find() -->

<arc:set attr="myString" value="Luke, I am your father". />
<arc:set attr="commaPosition" value="[myString | find(',')]" />
<arc:set attr="introClause" value="[myString | substring(0, [commaPosition])]" />
<!-- introClause has the value: Luke -->
```

## toalpha()

只返回字符串中的字母。

## toalphanum()

只返回字符串中的字母数字字符。

## truncate(integer\_count)

将属性值截断为参数指定的字符数。

* **count**：结果字符串中的字符数。
