apoc.text.indexOf

This function is deprecated. Use Cypher’s string.indexOf() function instead.

Details

Syntax

apoc.text.indexOf(text, lookup [, from, to ])

Description

Returns the first occurrence of the lookup STRING in the given STRING, or -1 if not found.

Arguments

Name

Type

Description

text

STRING

The string to search for the lookup string in.

lookup

STRING

The lookup string to search for in the given string.

from

INTEGER

The index at which to start the search. The default is: 0.

to

INTEGER

The index at which to stop the search. The default is: -1.

Returns

INTEGER

Usage Examples

The following returns the first occurrence of the lookup string in the given string using both APOC and Cypher:

apoc.text.indexOf
RETURN apoc.text.indexOf("Hello World", 'Hello') AS output;
Using Cypher’s string.indexOf
RETURN string.indexOf("Hello World", 'Hello') AS output;
Results
output

0

The following returns the first occurrence of 'Hello' starting from index 3 using both APOC and Cypher:

apoc.text.indexOf
RETURN apoc.text.indexOf("Hello World, Hello", 'Hello', 3) AS output;
Using Cypher’s string.indexOf
WITH 3 AS start
RETURN string.indexOf(substring("Hello World, Hello", start), 'Hello') + start AS output;
Results
output

13