Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
10-28-2019 01:32 PM
Dear Everyone,
I have a situation where I have a field with a price in it, but it also has the euro sign in the field (See attachment)/ What I would like to do is import the data from that JSON key value pair, but remove the euro sign, remove the empty space between the euro sign and price and also convert remaining information to integer (toInteger function).
I have been trying trim string function, replace string function on the field, but it doesn't work.
I tried to replace with a blank space then checked to see if using a letter "e" would be allowed (debugging). Only got errors
I read all over the Neo4J manual to see if there was a function, but to no avail. The strange thing is I have never seen anyone cleanup data before entering it into the database in any of the courses or youtube tutorials. I was even thinking to use regEx, but once I have the pattern, I do see how I can store just the selected result into some sort of variable or have that as a output for the relationship property.
10-29-2019 06:36 AM
Hey,
I tried more or less the same thing as you but the replace does work for me. See below:
call apoc.load.json("file:///foo.json")
YIELD value
RETURN replace(value.value, "€", "")
10-29-2019 06:38 AM
Hello Mark,
What about the issue with the back ticks being in there. Does that cause an issue?
In one of my attempts I did try Replace, but maybe I missed something.
Greetings
10-29-2019 06:42 AM
We can still use the same approach. See the example below:
call apoc.load.json("file:///foo.json")
YIELD value
RETURN replace(value.`value with spaces`, "€", "")
10-29-2019 06:45 AM
Here is my version that I did, but I must be missing something.
10-29-2019 06:50 AM
I just learned something. It has to be after the Return statement. So does this mean that Replace always need a place to put it's output?
Before I attempt to put it in a property in a database. I must ask. How does replace work in general?
I read the manual multiple times while trying the last days, and nowhere did it mention this gotcha about having to be before the return clause, or even how it is to be used in conjunction with other things.
It worked!!!!
But can you explain the above question about the best practices with replace?
Greetings,
Jeffrey
10-29-2019 06:56 AM
Trying to turn it into an integer gave the following incorrect end result
10-29-2019 07:01 AM
There was a space after the euro sign, so the toInterger was having problems with it, and also I needed a float. This finally gave me the end result I wanted.
See attachment
10-29-2019 07:03 AM
Mark,
How do I deal with more complex combinations that redEx normally can take of?
Say for instance that the euro sign was at the end.
Thanks for all your help thus so far.
10-30-2019 04:52 AM
Hi,
I think it might be worth looking at APOC, which is Neo4j's standard library, if you haven't used it yet. There are a bunch of useful functions and procedures in there, one of which is handy for doing text wrangling:
RETURN toInteger(apoc.text.replace('€4000€', '€', ''))
https://neo4j.com/docs/labs/apoc/current/misc/text-functions/#text-functions-regex
You can find installation instructions for the library here - https://neo4j.com/docs/labs/apoc/current/introduction/#installation
All the sessions of the conference are now available online