update:
Thanks for helping out. Actually I used the CSV parser to get what I want but I ask just because I want to know how the inner part of CSV parser works.
It's a part from Google Analytics CSV report. Actually I have found many other libs to retrieve what I want but I just really want to know what is the best way to get the data I want from this particular case. Though at first it looks not that hard, it's getting my crazy...
The data looks like this as a string:
/page1/index.php,"795,852","620,499",00:03:25,"33,416",10.82%,66.43%,$0.00
The string /page1/index.php is a page's name.
The first number "795,852" is the page view
The second number "620,499" is the unique page view
then with the avg. duration time.
Then I want to parse it to an object as:
{
page: "/page1/index.php"
pv: 795852
uv: 620499
avg_time:"00:03:25"
}
For some reasons, I only need to keep the first four data from this string. When I try to use a simple JavaScript code to parse, everything works fine until I found something different when the "pageviews" data are small.
For instance, sometimes it looks like:
/page2/index.php,"795,852",620,00:03:25,"33,416",10.82%,66.43%,$0.00
Or:
/page3/index.php,852,"620,499",00:03:25,"33,416",10.82%,66.43%,$0.00
Or:
/page4/index.php,852,620,00:03:25,"33,416",10.82%,66.43%,$0.00
The rule is: when the number is bigger than a thousand, it is written as
"795,852"
But when the number is smaller, it's just
852
There is no "" with it and of course, no , as the splitter. This makes it very hard to use just Regular Expression to get the data.
This makes it very difficult to parse the string into a wanted object, something like:
{
page: "/page1/index.php"
pv: 795852
uv: 620499
avg_time:"00:03:25"
}
any good ideas on parsing this with JavaScript?