---
schema_version: "1"
id: 8ba5ac59617c226c0d2a47e56192167f7e48fda44461e9835883220401f452a7
title: index_of()
collection: developer
version: current
locale: en-us
portal_url: https://docs.salesforce.com/developer/current/en-us/analytics/bi_dev_guide_saql/guides/reference/bi-saql-functions-string-io.md
canonical_url: https://developer.salesforce.com/docs/analytics/bi-dev-guide-saql/guide/bi-saql-functions-string-io.html
source_site: developer.salesforce.com
content_type: documentation
content_hash: a9963a5c6bab9b4736257eb3dd9010c74286c550e3f32f98e0436f768240dbbc
products:
  - Analytics SAQL Developer Guide
  - analytics
---

# index_of()

Returns the location (index) of the specified characters.

## Syntax

`index_of`(_string_, _searchStr_ [,_position_ [, _occurence_]])

## Usage

This function returns the index of _searchStr_ in _string_, beginning at the specified _position_. The function returns 0 if _searchStr_ is not found. This function is case-sensitive. If any of the parameters are _null_, then the function returns _null_.

The default value of _position_ is 1, which means that the function begins searching at the first character of _string_. An error results if _position_ is negative or zero.

_occurrence_ is an optional integer, with a default value of `1` . You can use this parameter to specify which occurrence of _searchStr_ to search for. For example, if there is more than one occurrence of _searchStr_, and _occurence_ is 2, the index of the second occurrence is returned.

Constant values are supported for _position_ and _occurrence_, not arbitrary expressions.

If _searchStr_ is an empty string, then the function returns _null_.

## Example

```nolang
q = load "Opportunity Details";
q = group q by all;
-- return the first occurrence of "a", starting at the beginning.
-- The result is 2.
q = foreach q generate index_of("Hawaii", "a") as 'Index';

-- return the second occurrence of "a", starting at the beginning
-- the result is 4
q = foreach q generate index_of("Hawaii", "a",1, 2) as 'Index';


-- return the first occurrence of "a", starting at the third position
-- the result is 4
q = foreach q generate index_of("Hawaii", "a",3) as 'Index';
```
