

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

# Locate
<a name="locate-function"></a>

`locate` 會找到您在另一個字串內指定的子字串，並傳回字元數，直到子字串中的第一個字元為止。如果找不到子字串，函數會傳回 0。該函數從 1 開始。

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

```
locate(expression, substring, start)
```

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

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

 *substring*   
您要尋找的 *expression* 中的一組字元。該子字串在 *expression* 中可能出現一或多次。

 *start*   
(選用) 如果 *substring* 出現不只一次，請使用 *start* 來識別字串中，函數應該開始尋找子字串的位置。例如，假設您想要找到子字串的第二個範例，並且您認為它一般會發生在前 10 個字元之後。您指定的 *start* 值為 10。應該從 1 開始。

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

Integer

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

以下範例會傳回有關字串中第一個出現子字串 'and' 的位置資訊。

```
locate('1 and 2 and 3 and 4', 'and')
```

會傳回下列值。

```
3
```

以下範例會傳回有關字串中第四個字元之後，第一個出現子字串 'and' 的位置資訊。

```
locate('1 and 2 and 3 and 4', 'and', 4)
```

會傳回下列值。

```
9
```