I need to extract certain characters from file name string from Dropbox. File in my Dropbox has the following format:
lettersanddigits - string.extension
I have successfully download the file with n8n and now I need to extract the first part of the filename to use in workflow. Filenames will be different in other files but keep the same format.
This is the part of the Dropbox JSON response where I can get the filename:
"name": "A02934024X - String.png",
I need help in order to extract the first part of filename.
There are a few ways you could do this, are the files always going to be pngs and is there a chance the string could contain a . in it?
You can use regex to match between 2 characters so in your example it would be anything between - and . but you could also use the string split method.
Ah ok so it is just the A02934024X that you would be after, That is handy. So one way you could do it would be to use variable_name.substr(0, variable_name.indexOf(' -')); where variable_name is your $json.name or whatever it might be.
If that first part is always 10 characters you could also do variable_name.substr(0,10) there is also the regex route but we can save that for later.
It isn’t pretty but the workflow below shows the first 2 in action using set nodes hopefully it helps.