

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# startsWith
<a name="startsWith-function"></a>

`startsWith` 會評估表達式是否以您指定的子字串開頭。如果表達式以相應子字符串開頭，則 `startsWith` 會返回 true，否則會返回 false。

## 語法
<a name="startsWith-function-syntax"></a>

```
startsWith(expression, substring, string-comparison-mode)
```

## 引數
<a name="startsWith-function-arguments"></a>

 *表達式*   
表達式必須是字串。它可以是使用字串資料類型的欄位、**'12 Main Street'** 之類的常值，或對輸出字串的另一個函數的呼叫。

 *substring*   
要針對表達式**檢查的字元集。該子字串在表達式**中可能出現一或多次。

 字串比較模式**   
(選用) 指定要使用的字串比較模式：  
+ `CASE_SENSITIVE`：字串比較區分大小寫。
+ `CASE_INSENSITIVE`：字串比較不區分大小寫。
空白時此值會預設為 `CASE_SENSITIVE`。

## 傳回類型
<a name="startsWith-function-return-type"></a>

Boolean

## 範例
<a name="startsWith-function-example"></a>

### 預設區分大小寫的範例
<a name="startsWith-function-example-default-case-sensitive"></a>

以下區分大小寫的範例評估 `state_nm` 是否以 **New** 開頭。

```
startsWith(state_nm, "New")
```

以下是指定欄位的值。

```
New York
new york
```

對於這些欄位值，會傳回以下值。

```
true
false
```

### 不區分大小寫的範例
<a name="startsWith-function-example-case-insensitive"></a>

以下不區分大小寫的範例評估 `state_nm` 是否以 **new** 開頭。

```
startsWith(state_nm, "new", CASE_INSENSITIVE)
```

以下是指定欄位的值。

```
New York
new york
```

對於這些欄位值，會傳回以下值。

```
true
true
```

### 條件陳述式範例
<a name="startsWith-function-example-conditional-statements"></a>

`startsWith` 函數可用作以下 If 函數中的條件陳述式：[avgIf](https://docs.aws.amazon.com/quicksight/latest/user/avgIf-function.html)、[minIf](https://docs.aws.amazon.com/quicksight/latest/user/minIf-function.html)、[distinct\$1countIf](https://docs.aws.amazon.com/quicksight/latest/user/distinct_countIf-function.html)、[countIf](https://docs.aws.amazon.com/quicksight/latest/user/countIf-function.html)、[maxIf](https://docs.aws.amazon.com/quicksight/latest/user/maxIf-function.html)、[medianIf](https://docs.aws.amazon.com/quicksight/latest/user/medianIf-function.html)、[stdevIf](https://docs.aws.amazon.com/quicksight/latest/user/stdevIf-function.html)、[stdevpIf](https://docs.aws.amazon.com/quicksight/latest/user/stdevpIf-function.html)、[sumIf](https://docs.aws.amazon.com/quicksight/latest/user/sumIf-function.html)、[varIf](https://docs.aws.amazon.com/quicksight/latest/user/varIf-function.html) 和 [varpIf](https://docs.aws.amazon.com/quicksight/latest/user/varpIf-function.html)。

以下範例僅當 state\$1nm 以 **New** 開頭時才對 `Sales` 求和。

```
sumIf(Sales,startsWith(state_nm, "New"))
```

### 不包含範例
<a name="startsWith-function-example-does-not-start-with"></a>

條件 `NOT` 運算子可用來評估表達式是否以指定的子字串開頭。

```
NOT(startsWith(state_nm, "New"))
```

### 使用數值的範例
<a name="startsWith-function-example-numeric-values"></a>

透過套用 `toString` 函數，可以在表達式或子字串引數中使用數值。

```
startsWith(state_nm, toString(5) )
```