> ## 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**：結果字串中的字元數。
