15

pretty simple question, is there a way to get length of a string in Neo4j cypher? I cannot find any document for that.

thanks

Qun Wang
  • 299
  • 1
  • 4
  • 7

4 Answers4

25

To return the length of a string in Cypher, use the SIZE() function. The LENGTH() function is now exclusively used for measuring PATHs in the graph.

RETURN size("This is an example string")

yields 25

From the good folks at Neo: "This feature is deprecated and will be removed in future versions. Using length on anything that is not a path is deprecated, please use size instead"

Adam Rentschler
  • 351
  • 3
  • 5
8

Try length(), like

RETURN length("hello world")

in 2.0 (return-only queries are new in 2.0) or

START n=node(5)
RETURN length(n.name)

or some such for 1.9.

jjaderberg
  • 9,844
  • 34
  • 34
5

You can use the length() scalar function like:

MATCH (n:Crew)-[r:KNOWS*]-m 
WHERE n.name='Neo' 
RETURN n AS Neo,r,m,length(n.name)

Check out this example here.

James
  • 11,654
  • 6
  • 52
  • 81
1

Make sure you read the manual. It has all of the information you need.

To return or filter on the length of a string, use the LENGTH() function. For example:

Return Length("Test !") 

result will be 6.

Lina
  • 1,217
  • 1
  • 15
  • 28