> ## 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 屬性值執行條件邏輯、比較以及 null/空檢查的格式化器。

## allownull()

如果屬性不存在則傳回 *NULL*，如果存在則傳回其值。

## contains(target\[, ifcontains]\[, ifnotcontains])

如果輸入字串包含 *target*，則傳回 *true*；否則傳回 *false*。

可以將 *ifcontains* 參數設定為在輸入字串包含 *target* 時傳回的替代值，也可以將 *ifnotcontains* 參數設定為在輸入字串不包含 *target* 時傳回的替代值。

### 範例

```xml theme={null}
<arc:set attr="myString" value="hello world" />
<arc:if exp="[myString | contains('hello')]">
  <arc:set attr="response" value="hello to you too!" />
  <arc:else>
    <arc:set attr="response" value="I would appreciate a greeting" />
  </arc:else>
</arc:if>
```

## def(ifnotexists\[, ifexists])

設定屬性的“預設”值。如果該屬性尚未設定值，則將其設定為 *ifnotexists* 中傳入的值；如果該屬性已存在，則將其設定為 *ifexists* 中傳入的值。

### 範例

```xml theme={null}
<!-- count the number of loops in an XML document using xmlDOMSearch -->

<arc:set attr="xml.uri" value="[FilePath]" />
<arc:set attr="xml.xpath" value="/Items/test/loop" />

<arc:call op="xmlDOMSearch" in="xml">
  <!-- this code executes for each occurrence of the 'xpath' in the XML document -->
  <arc:set attr="loopCount" value="[loopCount | def(0) | add(1)]" />
</arc:call>
```

## empty(value)

如果屬性值為空，則傳回指定的值；否則傳回原始屬性值。

* **value**：屬性為空時要使用的值。

## equals(value\[, ifequal]\[, ifnotequal])

如果輸入屬性與 *value* 匹配，則傳回 *true*；否則傳回 *false*。

如果提供了 *ifequal* 和/或 *ifnotequal*，則傳回這些參數中的值，而不是 *true* 和 *false*。

### 範例

```xml theme={null}
<arc:set attr="myItem.code" value="[xpath(data/lineitems/itemcode)]" />
<arc:if exp="[myItem.code | equals('A5')]">
  <arc:set attr="myItem.name" value="spoon" />
  <arc:else>
    <arc:set attr="myItem.name" value="fork" />
  </arc:else>
</arc:if>
```

## ifequal(value\[, ifequals]\[, ifnotequals])

將屬性值與第一個參數值進行比較。如果它們相等，則傳回 *true*（或 *ifequals*）；如果不相等，則傳回 *false*（或 *ifnotequals*）。

* **value**：要與屬性值進行比較的字串。
* **ifequals**：可選值，如果屬性值等於第一個參數表示的值，則傳回此值。
* **ifnotequals**：可選值，如果屬性值不等於第一個參數表示的值，則傳回此值。

## ifmatches(value\[, ifmatch]\[, ifnotmatch])

如果屬性值與第一個參數匹配，則傳回 *true*（或 *ifmatch*）；否則傳回 *false*（或 *ifnotmatch*）。

* **value**：要與屬性值進行比較的值。
* **ifmatch**：可選值，如果屬性值與參數值匹配，則傳回此值。
* **ifnotmatch**：可選值，如果屬性值與參數值不匹配，則傳回此值。

## isalphabetic(\[ifalpha]\[, ifnotalpha])

如果屬性值中的所有字元都是字母且至少有一個字元，則傳回 *true*（或 *ifalpha*）；否則傳回 *false*（或 *ifnotalpha*）。

* **ifalpha**：可選值，如果屬性值是字母字串，則傳回此值。
* **ifnotalpha**：可選值，如果屬性值不是字母字串，則傳回此值。

## isalphanumeric(\[ifalphanum]\[, ifnotalphanum])

如果屬性值中的所有字元都是字母數字字元且至少有一個字元，則傳回 *true*（或 *ifalphanum*）；否則傳回 *false*（或 *ifnotalphanum*）。

* **ifalphanum**：可選值，如果屬性值只包含字母或數字字元，則傳回此值。
* **ifnotalphanum**：可選值，如果屬性值包含非字母或非數字字元，則傳回此值。

## islower(\[iflower]\[, ifnotlower])

如果屬性值中的所有字母都是小寫且至少有一個字元是字母，則傳回 *true*（或 *iflower*）；否則傳回 *false*（或 *ifnotlower*）。

* **iflower**：可選值，如果屬性值為小寫，則傳回此值。
* **ifnotlower**：可選值，如果屬性值不是小寫，則傳回此值。

## isnumeric(\[ifnum]\[, ifnotnum])

如果屬性值中的所有字元都是數字且至少有一個字元，則傳回 *true*（或 *ifnum*）；否則傳回 *false*（或 *ifnotnum*）。

* **ifnum**：可選值，如果屬性值是數字，則傳回此值。
* **ifnotnum**：可選值，如果屬性值不是數字，則傳回此值。

## isspace(\[ifspace]\[, ifnotspace])

如果屬性值中只有空白字元且至少有一個字元，則傳回 *true*（或 *ifspace*）；否則傳回 *false*（或 *ifnotspace*）。

* **ifspace**：可選值，如果屬性值為空白字元，則傳回此值。
* **ifnotspace**：可選值，如果屬性值不是空白字元，則傳回此值。

## isupper(\[ifupper]\[, ifnotupper])

如果屬性值中的所有字母都是大寫且至少有一個字元是字母，則傳回 *true*（或 *ifupper*）；否則傳回 *false*（或 *ifnotupper*）。

* **ifupper**：可選值，如果屬性值為大寫，則傳回此值。
* **ifnotupper**：可選值，如果屬性值不是大寫，則傳回此值。

## notequals(value\[, notequals]\[, equals])

將屬性值與第一個參數值進行比較。如果它們不相等，則傳回 *true*（或 *notequals*）；如果相等，則傳回 *false*（或 *equals*）。

* **value**：要與屬性值進行比較的字串。
* **notequals**：可選值，如果屬性值不等於第一個參數表示的值，則傳回此值。
* **equals**：可選值，如果屬性值等於第一個參數表示的值，則傳回此值。

## startswith(target\[, iftrue]\[, iffalse])

如果輸入字串以 *target* 指定的值開頭，則傳回 *true*；否則傳回 *false*。

如果提供了 *iftrue*，當找到 *target* 時會傳回該值而不是 *true*；如果提供了 *iffalse*，當未找到 *target* 時會傳回該值而不是 *false*。

### 範例

```xml theme={null}
<arc:set attr="myString" value="Sir, your carriage is ready." />
<arc:if exp="[myString | startswith('Sir')]">
  <arc:set attr="response" value="Thank you." />
  <arc:else>
    <arc:set attr="response" value="Use your manners." />
  </arc:else>
</arc:if>
```
