trouble with split() and also weird quotes around a key in the object

I have a csv file which I'm going through each line and spliting it with text.split(",");. However, the problem is when I go to titles like this: "Pokemon: Let's Go, Pikachu/Eevee". This splits into "Pokemon: Let's Go, Pikachu and /Eevee" instead of "Pokemon: Let's Go, Pikachu/Eevee". Dose anyone know a way around this? I know that it will split because it has , in the title but is there a way around this? Maybe something like only split , if not surrounded by " " quotes?
34 Replies
kingtigerknight
kingtigerknight•2y ago
Here is my code
kingtigerknight
kingtigerknight•2y ago
Here is the csv file, theres like 4 thousand lines so this is basically the format
kingtigerknight
kingtigerknight•2y ago
Also the year is somehow "Year " which is weird since I'm not sure what cause it to have quotes around it
MarkBoots
MarkBoots•2y ago
Here i can not see the " " quotes surrounding the different cells, so there is no way to distinguish it. Did you create the svg youself ? (Maybe you can change the delimiter to another character on export)
kingtigerknight
kingtigerknight•2y ago
The csv file?
MarkBoots
MarkBoots•2y ago
yea
kingtigerknight
kingtigerknight•2y ago
Ah no, It's downloaded. I could edit each of the maybe thousands of names but... thats a lot XD
MarkBoots
MarkBoots•2y ago
maybe, if we can be sure that comma's in normal text have a space behind it, we can split only if there are no spaces
kingtigerknight
kingtigerknight•2y ago
kingtigerknight
kingtigerknight•2y ago
Heres the one I was talking about
MarkBoots
MarkBoots•2y ago
ah okay... that looks bettere we need to use some regex (im not an expert), but will try to look
kingtigerknight
kingtigerknight•2y ago
Yeah, thats what I need looking for. Especially when some of the commas are not in quotation marks so that is going to be a problem XD
MarkBoots
MarkBoots•2y ago
Stack Overflow
Split a string by commas but ignore commas within double-quotes usi...
I'm looking for [a, b, c, "d, e, f", g, h]to turn into an array of 6 elements: a, b, c, "d,e,f", g, h. I'm trying to do this through Javascript. This is what I have so far: str = str.split(/,+|"[^...
kingtigerknight
kingtigerknight•2y ago
Oh yeah I looked at that one, sadly it removes the title completely XD
MarkBoots
MarkBoots•2y ago
this some seems to do the trick example: https://codepen.io/MarkBoots/pen/BaVKOOM?editors=1011 (check console)
kingtigerknight
kingtigerknight•2y ago
😮 Now that I think about it, there isn't a way for this is there? Because some titles have commas in it with and without quotes. Hmmmm so that means I'll need to combination of two methods?... oh dear... XD
MarkBoots
MarkBoots•2y ago
if there are no quotes, then i don't think there is a way js does not know what is a title or not, it just sees comma's
kingtigerknight
kingtigerknight•2y ago
Hmm, yeah I'll check the codepen out and see if there is any other problems with the titles XD btw do you know why the "Year " is in quotes?
MarkBoots
MarkBoots•2y ago
because there is a space.
kingtigerknight
kingtigerknight•2y ago
AHHH ok Thanks for the help 🙂
MarkBoots
MarkBoots•2y ago
just trim that value, or remove manualy no problem, good luck can i ask where you downloaded that svg? fun exersize
kingtigerknight
kingtigerknight•2y ago
Video Game Sales Data
video game sales data including games from 1977 to 2020
kingtigerknight
kingtigerknight•2y ago
You'll need to make an account but it's free 😄 At least I hope so, I'm downloading it from my school account so It might no be free if your not in the class XD
MarkBoots
MarkBoots•2y ago
here, i exported it to json
kingtigerknight
kingtigerknight•2y ago
what? how? HM? XD
MarkBoots
MarkBoots•2y ago
download the csv, opened it in excel and with a script exported to json. now you're done with all that reading/splitting, bla bla bla
kingtigerknight
kingtigerknight•2y ago
when you started the project about 7+ hours ago trying to debug and finding a way to read the file and split but I could have just used excel. I'm dead XD
MarkBoots
MarkBoots•2y ago
it happens. when im working with data, i allways ask the question first. Can i alter the data in a way that makes handling it a lot easier
kingtigerknight
kingtigerknight•2y ago
Ah I never thought of that, I kind of just wonder who to make it work with javascript instead of useing node or other APIs. Time to start doing that XD Thanks for the help times 2 😄
MarkBoots
MarkBoots•2y ago
no problem mate
kingtigerknight
kingtigerknight•2y ago
OH! btw how did you script exported to json in excel?
MarkBoots
MarkBoots•2y ago
I have that script a long time, written in vba. But i found an even easier way https://csvjson.com/csv2json just paste the csv
kingtigerknight
kingtigerknight•2y ago
Ahhh ok thanks 😄
13eck
13eck•2y ago
Next time be sure to follow #How To Ask Good Questions and not post screenshots of code.
Want results from more Discord servers?
Add your server