---
layout: Conceptual
monikers:
- microsoft-sentinel
- azure-monitor
- azure-data-explorer
- microsoft-fabric
defaultMoniker: microsoft-fabric
versioningType: Ranged
title: indexof（） - Azure Data Explorer & Real-Time Intelligence | Azure Docs
canonicalUrl: https://docs.azure.cn/zh-cn/data-explorer/kusto/query/indexof-function?view=microsoft-fabric
schema: Conceptual
author: alexchen2016
breadcrumb_path: /bread/toc.json
default_moniker: microsoft-fabric
depot_name: Azure.mooncake-docs
description: 了解如何使用 indexof() 函数报告输入字符串的索引位置（从零开始）。
document_id: 5c9e52fc-1dfe-3f8c-1498-56f60c08c52e
document_version_independent_id: 56baa205-8d8e-c5bb-37bd-60a886244f75
git_commit_id: 0bba458f49fa43e64f86f3fd5cf02c182cc7db6e
gitcommit: https://github.com/MicrosoftDocs/mc-docs-pr/blob/0bba458f49fa43e64f86f3fd5cf02c182cc7db6e/articles/data-explorer/kusto/query/indexof-function.md
locale: zh-cn
monikers:
- microsoft-sentinel
- azure-monitor
- azure-data-explorer
- microsoft-fabric
ms.author: v-junlch
ms.date: 2025-05-04T00:00:00.0000000Z
ms.reviewer: alexans
ms.service: azure-data-explorer
ms.topic: reference
original_content_git_url: https://github.com/MicrosoftDocs/mc-docs-pr/blob/live/articles/data-explorer/kusto/query/indexof-function.md
recommendations: false
site_name: DocsAzureCN
uhfHeaderId: mooncake
updated_at: 2026-03-10T11:00:00.0000000Z
ms.translationtype: MT
ms.contentlocale: zh-cn
loc_version: 2026-02-28T10:15:01.6557296Z
loc_source_id: Github-85544329#live
loc_file_id: Github-85544329.live.Azure.mooncake-docs.articles/data-explorer/kusto/query/indexof-function.md
page_type: conceptual
toc_rel: ../toc.json
feedback_system: None
feedback_product_url: ''
feedback_help_link_type: ''
feedback_help_link_url: ''
word_count: 487
asset_id: data-explorer/kusto/query/indexof-function
item_type: Content
cmProducts:
- https://authoring-docs-microsoft.poolparty.biz/devrel/26e1a60c-4ce1-41de-b2d1-e5f3b7e68e6e
- https://microsoft-devrel.poolparty.biz/DevRelOfferingOntology/12ed19f9-ebdf-4c8a-8bcd-7a681836774d
- https://authoring-docs-microsoft.poolparty.biz/devrel/540ac133-a371-4dbb-8f94-28d6cc77a70b
spProducts:
- https://authoring-docs-microsoft.poolparty.biz/devrel/ad3bd485-5ca9-4865-afde-baec02586899
- https://microsoft-devrel.poolparty.biz/DevRelOfferingOntology/3a764584-4f97-452b-8f1d-36f19b12f6ae
- https://authoring-docs-microsoft.poolparty.biz/devrel/60bfc045-f127-4841-9d00-ea35495a5800
platformId: 1aedc75f-6f1d-bd8c-bc41-fbf8d353271c
---

# indexof（） - Azure Data Explorer & Real-Time Intelligence | Azure Docs

> 
> 使用 **“版本** ”下拉列表切换服务。 [了解有关导航的详细信息](../docs-navigation)。  适用于：✅ Azure Data Explorer ✅ Azure Monitor ✅ Microsoft Sentinel

报告输入字符串中指定的字符串第一次出现时的索引（从零开始）。 `indexof()` 函数区分大小写。 若要执行不区分大小写的搜索，请考虑使用或`tolower()`同时使用`toupper()`这两种输入。

有关详细信息，请参阅 [`indexof_regex()`](indexof-regex-function)。

## 语法

`indexof(`*字符串*`,`*火柴*`[,`*开始*`[,`*长度*`[,`*发生*`]]])`

详细了解[语法约定](/zh-cn/data-explorer/kusto/query/syntax-conventions)。

## 参数

| 客户 | 类型 | 必需 | 说明 |
| --- | --- | --- | --- |
| *字符串* | `string` | ✔️ | 要搜索的源字符串。 |
| match | `string` | ✔️ | 要搜索的字符串。 |
| *开始* | `int` |  | 搜索开始位置。 如果是负值，则将从 string 的末尾起，将起始搜索位置偏移以下步数：start`abs(`。 |
| *长度* | `int` |  | 要检查的字符位置数。 值为 -1 表示长度没有限制。 |
| *事件* | `int` |  | 出现的次数。 默认值为 1。 |

注意

如果 string 或 match 不属于  类型，则此函数会将其值强制转换为 。

## 返回

match 的索引位置（从零开始）。

- 如果在 string 中找不到 match，则返回 -1。
- 如果符合以下条件，则返回 `null`：
    - start 小于 0。
    - occurrence 小于 0。
    - length 小于 -1。

## 示例

```kusto
print
 idx1 = indexof("abcdefg","cde")    // lookup found in input string
 , idx2 = indexof("abcdefg","cde",1,4) // lookup found in researched range 
 , idx3 = indexof("abcdefg","cde",1,2) // search starts from index 1, but stops after 2 chars, so full lookup can't be found
 , idx4 = indexof("abcdefg","cde",3,4) // search starts after occurrence of lookup
 , idx5 = indexof("abcdefg","cde",-5)  // negative start index
 , idx6 = indexof(1234567,5,1,4)       // two first parameters were forcibly casted to strings "12345" and "5"
 , idx7 = indexof("abcdefg","cde",2,-1)  // lookup found in input string
 , idx8 = indexof("abcdefgabcdefg", "cde", 1, 10, 2)   // lookup found in input range
 , idx9 = indexof("abcdefgabcdefg", "cde", 1, -1, 3)   // the third occurrence of lookup is not in researched range
```

**输出**

| idx1 | idx2 | idx3 | idx4 | idx5 | idx6 | idx7 | idx8 | idx9 |
| --- | --- | --- | --- | --- | --- | --- | --- | --- |
| 2 | 2 | -1 | -1 | 2 | 4 | 2 | 9 | -1 |