Jeroen Steen
Jeroen Steen

Reputation: 541

Remove whitespace with Cypher in Neo4j

How can I remove whitespace in a certain property value. The amount of whitespace is different per node.

The values look like this:

"3220       BA"

"3223   NA"

"3231           MA"

Does something like preg replace \s exist in Cypher?

Upvotes: 2

Views: 3256

Answers (4)

Ilya Kushlianski
Ilya Kushlianski

Reputation: 968

For anyone facing non-breaking spaces instead of usual spaces, compare:

'ADP 5140'.split('').map(char => char.charCodeAt(0))[3] // 160

and

'ADP 5140'.split('').map(char => char.charCodeAt(0))[3] // 32

So I had to include in my Cypher the logic for removing both usual (ASCII code 32) and non-breaking (ASCII code 160) spaces:

return replace(replace('ADP 2119', ' ', ''), ' ', '')

Upvotes: 0

manonthemat
manonthemat

Reputation: 6251

Try this:

CREATE (t:Test { prop: 'Tooo        many     whitespaces'}) 
MATCH (t:Test) SET t.prop = replace(t.prop, " ", "") RETURN t

Upvotes: 0

stdob--
stdob--

Reputation: 29172

Try replace:

replace( "3220       BA", " ", "" )

Upvotes: 1

mohit sharma
mohit sharma

Reputation: 1070

Try this,

trim({original}), ltrim({original}),
 rtrim({original})

Trim all whitespace, or on left or right side

for Reference, Follow below link http://neo4j.com/docs/pdf/neo4j-cypher-refcard-stable.pdf

Upvotes: 2

Related Questions