How do I get the first position of a substring in a string


(Clooney24) #1

I'm looking for a simple string function to get the first position of a substring in a string. Something equivalent of indexOf(), strPos(), charIndex()... Didn't find anything in Cypher or Apoc - only issue 1041, open since 2013?


(Michael Hunger) #2

There is nothing direct in Cypher. I was totally sure we already had it in apoc.
Gonna add it this week.

As a workaround in the meantime you can use split + length:

RETURN length(split("ab-c","-")[0])

Added an issue here: https://github.com/neo4j-contrib/neo4j-apoc-procedures/issues/896