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
Here is my code
Here is the csv file, theres like 4 thousand lines so this is basically the format
Also the year is somehow
"Year "
which is weird since I'm not sure what cause it to have quotes around itHere 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)
The csv file?
yea
Ah no, It's downloaded. I could edit each of the maybe thousands of names but... thats a lot XD
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
Heres the one I was talking about
ah okay... that looks bettere
we need to use some regex (im not an expert), but will try to look
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
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(/,+|"[^...
Oh yeah I looked at that one, sadly it removes the title completely XD
this some seems to do the trick
example: https://codepen.io/MarkBoots/pen/BaVKOOM?editors=1011
(check console)
😮
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
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
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?because there is a space.
AHHH ok
Thanks for the help 🙂
just trim that value, or remove manualy
no problem, good luck
can i ask where you downloaded that svg? fun exersize
Video Game Sales Data
video game sales data including games from 1977 to 2020
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
here, i exported it to json
what? how? HM?
XD
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
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
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
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 😄
no problem mate
OH! btw how did you script exported to json in excel?
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
Ahhh ok thanks 😄
Next time be sure to follow #How To Ask Good Questions and not post screenshots of code.