Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #37826 > unrolled thread
| Started by | Jonas Thörnvall <jonas.thornvall@gmail.com> |
|---|---|
| First post | 2019-11-22 02:10 -0800 |
| Last post | 2019-11-23 18:56 -0800 |
| Articles | 10 on this page of 30 — 6 participants |
Back to article view | Back to comp.lang.javascript
Parse out after newline and paragraph? Jonas Thörnvall <jonas.thornvall@gmail.com> - 2019-11-22 02:10 -0800
Re: Parse out after newline and paragraph? JJ <jj4public@vfemail.net> - 2019-11-22 18:36 +0700
Re: Parse out after newline and paragraph? Jonas Thörnvall <jonas.thornvall@gmail.com> - 2019-11-22 03:58 -0800
Re: Parse out after newline and paragraph? Jonas Thörnvall <jonas.thornvall@gmail.com> - 2019-11-22 04:09 -0800
Re: Parse out after newline and paragraph? JJ <jj4public@vfemail.net> - 2019-11-23 08:38 +0700
Re: Parse out after newline and paragraph? Jonas Thörnvall <jonas.thornvall@gmail.com> - 2019-11-22 23:31 -0800
Re: Parse out after newline and paragraph? John G Harris <niam@jghnorth.org.uk.invalid> - 2019-11-22 18:25 +0000
Re: Parse out after newline and paragraph? Jonas Thörnvall <jonas.thornvall@gmail.com> - 2019-11-22 11:09 -0800
Re: Parse out after newline and paragraph? John G Harris <niam@jghnorth.org.uk.invalid> - 2019-11-23 10:51 +0000
Re: Parse out after newline and paragraph? Jonas Thörnvall <jonas.thornvall@gmail.com> - 2019-11-23 05:04 -0800
Re: Parse out after newline and paragraph? John G Harris <niam@jghnorth.org.uk.invalid> - 2019-11-23 18:37 +0000
Re: Parse out after newline and paragraph? Jonas Thörnvall <jonas.thornvall@gmail.com> - 2019-11-24 09:58 -0800
Re: Parse out after newline and paragraph? John G Harris <niam@jghnorth.org.uk.invalid> - 2019-11-24 18:51 +0000
Re: Parse out after newline and paragraph? Jonas Thörnvall <jonas.thornvall@gmail.com> - 2019-11-24 10:01 -0800
Re: Parse out after newline and paragraph? John G Harris <niam@jghnorth.org.uk.invalid> - 2019-11-24 19:28 +0000
Re: Parse out after newline and paragraph? Jonas Thörnvall <jonas.thornvall@gmail.com> - 2019-11-25 01:19 -0800
Re: Parse out after newline and paragraph? John G Harris <niam@jghnorth.org.uk.invalid> - 2019-11-25 18:28 +0000
Re: Parse out after newline and paragraph? Jonas Thörnvall <jonas.thornvall@gmail.com> - 2019-11-26 04:24 -0800
Re: Parse out after newline and paragraph? Jonas Thörnvall <jonas.thornvall@gmail.com> - 2019-11-27 05:41 -0800
Re: Parse out after newline and paragraph? Jonas Thörnvall <jonas.thornvall@gmail.com> - 2019-11-30 08:47 -0800
Re: Parse out after newline and paragraph? "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2019-11-30 10:38 -0800
Re: Parse out after newline and paragraph? Jonas Thörnvall <jonas.thornvall@gmail.com> - 2019-11-30 11:21 -0800
Re: Parse out after newline and paragraph? "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2019-11-22 10:43 -0800
Re: Parse out after newline and paragraph? Jonas Thörnvall <jonas.thornvall@gmail.com> - 2019-11-22 11:11 -0800
Re: Parse out after newline and paragraph? luserdroog <luser.droog@gmail.com> - 2019-11-23 12:09 -0800
Re: Parse out after newline and paragraph? Julio Di Egidio <julio@diegidio.name> - 2019-11-23 18:21 -0800
Re: Parse out after newline and paragraph? Julio Di Egidio <julio@diegidio.name> - 2019-11-23 19:08 -0800
Re: Parse out after newline and paragraph? luserdroog <luser.droog@gmail.com> - 2019-11-23 19:52 -0800
Re: Parse out after newline and paragraph? Julio Di Egidio <julio@diegidio.name> - 2019-11-23 21:54 -0800
Re: Parse out after newline and paragraph? luserdroog <luser.droog@gmail.com> - 2019-11-23 18:56 -0800
Page 2 of 2 — ← Prev page 1 [2]
| From | "Michael Haufe (TNO)" <tno@thenewobjective.com> |
|---|---|
| Date | 2019-11-30 10:38 -0800 |
| Message-ID | <3e8573d9-58fd-49a5-9062-b46524def642@googlegroups.com> |
| In reply to | #37908 |
On Saturday, November 30, 2019 at 10:47:34 AM UTC-6, Jonas Thörnvall wrote: > Managed to parse out the CC values on each channel now i just must push them with notes and sort the track. > > I must say that Javascript string handling is excellent for parsing makes it very easy, well done to whoever thought that one out. Split, substring, indexoff and replace and you parse out with ease at least from "strings". > > I like it, i was thinking this was going to take weeks, more like 10 hours. > That is a sign someone done something right. If you used `JSON.parse` like I and others suggested it would have taken you minutes...
[toc] | [prev] | [next] | [standalone]
| From | Jonas Thörnvall <jonas.thornvall@gmail.com> |
|---|---|
| Date | 2019-11-30 11:21 -0800 |
| Message-ID | <b0276f66-e620-4271-9121-154f4078b750@googlegroups.com> |
| In reply to | #37909 |
Den lördag 30 november 2019 kl. 19:38:18 UTC+1 skrev Michael Haufe (TNO): > On Saturday, November 30, 2019 at 10:47:34 AM UTC-6, Jonas Thörnvall wrote: > > > Managed to parse out the CC values on each channel now i just must push them with notes and sort the track. > > > > I must say that Javascript string handling is excellent for parsing makes it very easy, well done to whoever thought that one out. Split, substring, indexoff and replace and you parse out with ease at least from "strings". > > > > I like it, i was thinking this was going to take weeks, more like 10 hours. > > That is a sign someone done something right. > > If you used `JSON.parse` like I and others suggested it would have taken you minutes... Well after i read upon how it works.....
[toc] | [prev] | [next] | [standalone]
| From | "Michael Haufe (TNO)" <tno@thenewobjective.com> |
|---|---|
| Date | 2019-11-22 10:43 -0800 |
| Message-ID | <03ef961e-c2dd-43b8-a909-e507361cc109@googlegroups.com> |
| In reply to | #37826 |
On Friday, November 22, 2019 at 4:10:20 AM UTC-6, Jonas Thörnvall wrote:
> ": [
> {
> "duration": 0.0881409374999933,
> "durationTicks": 22,
> "midi": 72,
> "name": "C5",
> "ticks": 13056,
> "time": 52.30764,
> "velocity": 0.952755905511811
>
> I try to parseout the time from string above, but i do not manage get rid of the comma after time event.
>
> It is probably because i do not know how to adjust relative the paragraph?
>
> impTimeStart=impNote[IN].indexOf('"time": ');
> impTimeEnd=impNote[IN].indexOf(',\n"velocity":');
> impTime=impNote[IN].substring(impTimeStart+8,impTimeEnd);
>
> I do not do much parsing so a full example, would be nice. Maybe i just do it a silly way to start with.
It looks like a JSON string, so use the api:
```javascript
let imp = JSON.parse(theString),
timeStart = imp.time,
timeEnd = imp.velocity,
...
```
[toc] | [prev] | [next] | [standalone]
| From | Jonas Thörnvall <jonas.thornvall@gmail.com> |
|---|---|
| Date | 2019-11-22 11:11 -0800 |
| Message-ID | <18ca2098-b44c-4ed1-b350-7d0ebee5cb28@googlegroups.com> |
| In reply to | #37837 |
Den fredag 22 november 2019 kl. 19:43:48 UTC+1 skrev Michael Haufe (TNO):
> On Friday, November 22, 2019 at 4:10:20 AM UTC-6, Jonas Thörnvall wrote:
> > ": [
> > {
> > "duration": 0.0881409374999933,
> > "durationTicks": 22,
> > "midi": 72,
> > "name": "C5",
> > "ticks": 13056,
> > "time": 52.30764,
> > "velocity": 0.952755905511811
> >
> > I try to parseout the time from string above, but i do not manage get rid of the comma after time event.
> >
> > It is probably because i do not know how to adjust relative the paragraph?
> >
> > impTimeStart=impNote[IN].indexOf('"time": ');
> > impTimeEnd=impNote[IN].indexOf(',\n"velocity":');
> > impTime=impNote[IN].substring(impTimeStart+8,impTimeEnd);
> >
> > I do not do much parsing so a full example, would be nice. Maybe i just do it a silly way to start with.
>
> It looks like a JSON string, so use the api:
>
> ```javascript
>
> let imp = JSON.parse(theString),
> timeStart = imp.time,
> timeEnd = imp.velocity,
> ...
> ```
I probably should learn use JSON maybe next project.
[toc] | [prev] | [next] | [standalone]
| From | luserdroog <luser.droog@gmail.com> |
|---|---|
| Date | 2019-11-23 12:09 -0800 |
| Message-ID | <5d681cbb-68c4-4ed8-9be5-c763e268d7aa@googlegroups.com> |
| In reply to | #37838 |
On Friday, November 22, 2019 at 1:11:14 PM UTC-6, Jonas Thörnvall wrote:
> I probably should learn use JSON maybe next project.
I think it is a very good idea to learn to use JSON, but there's no
need to wait! You probably already know the details, you just don't
know that you know.
JSON stands for JavaScript Object Notation. It's just the normal
syntax for describing data that you already use everywhere in
JavaScript. The only difference is that it is embedded or serialized
in strings, or stored in a file.
So if you have a data structure defined in a variable, like
var data = { key: 'value', number: 42, array: [ 'x', 'y', 'z' ] };
Then you have a built-in function for serializing it to a string,
after which it can easily be stored in a file, session storage,
database, etc.
var datastring = JSON.stringify( data );
console.log(datastring);
//=> {"key":"value","number":42,"array":["x","y","z"]}
Conversely, if you have a JSON string from somewhere (file, database,
API, etc.), then you can easily get the data back out in a usable
form.
var datarestored = JSON.parse( datastring );
console.log( datarestored );
//=> Object { key: "value", number: 42, array: (3) [...] }
It's really super easy. JSON.stringify() and JSON.parse() for
serializing and de-serializing.
I think Regex is also valuable to learn, but that may take more
time. Maybe that's something to save for the next project.
But using JSON functions will save you much time and headache,
especially if your midi parsing library already provides a
JSON string as its output.
[toc] | [prev] | [next] | [standalone]
| From | Julio Di Egidio <julio@diegidio.name> |
|---|---|
| Date | 2019-11-23 18:21 -0800 |
| Message-ID | <4395e3e1-ffb2-4f54-9929-4e4e2d04451e@googlegroups.com> |
| In reply to | #37850 |
On Saturday, 23 November 2019 21:09:31 UTC+1, luserdroog wrote: > On Friday, November 22, 2019 at 1:11:14 PM UTC-6, Jonas Thörnvall wrote: > > > I probably should learn use JSON maybe next project. > > I think it is a very good idea to learn to use JSON, but there's no > need to wait! You probably already know the details, you just don't > know that you know. > > JSON stands for JavaScript Object Notation. It's just the normal > syntax for describing data that you already use everywhere in > JavaScript. The only difference is that it is embedded or serialized > in strings, or stored in a file. That is not true: there are some differences between JSON and JS proper, and they are going to bite you back at the first non-trivial application if you aren't aware of them... Julio
[toc] | [prev] | [next] | [standalone]
| From | Julio Di Egidio <julio@diegidio.name> |
|---|---|
| Date | 2019-11-23 19:08 -0800 |
| Message-ID | <5d9a09a9-5a47-47c3-a9b1-e7dc6f70da7a@googlegroups.com> |
| In reply to | #37852 |
On Sunday, 24 November 2019 03:57:05 UTC+1, luserdroog wrote: > On Saturday, November 23, 2019 at 8:21:10 PM UTC-6, Julio Di Egidio wrote: > > On Saturday, 23 November 2019 21:09:31 UTC+1, luserdroog wrote: > > > On Friday, November 22, 2019 at 1:11:14 PM UTC-6, Jonas Thörnvall wrote: > > > > > > > I probably should learn use JSON maybe next project. > > > > > > I think it is a very good idea to learn to use JSON, but there's no > > > need to wait! You probably already know the details, you just don't > > > know that you know. > > > > > > JSON stands for JavaScript Object Notation. It's just the normal > > > syntax for describing data that you already use everywhere in > > > JavaScript. The only difference is that it is embedded or serialized > > > in strings, or stored in a file. > > > > That is not true: there are some differences between JSON and JS proper, > > and they are going to bite you back at the first non-trivial application > > if you aren't aware of them... > > With all due respect, that's just FUD. I may well be ignoring some > details. But OP already has JSON data produced by the library he's > using. That's half of the equation already done. Finito. > > Using JSON.parse() to interpret that data would already > have saved the several days work he's already invested in writing > lots of fiddly code to parse it. Starting to use it now, even if > difficulties arise (which he will likely post about and receive > help with) the will be orders of magnitude less effort than continuing > down the current path. I have not said JSON is not the way to go, that's fine: I just said be careful with it (aka, look up the details in the documentation, sooner or later) for it is *not* just JS syntax, and it *is* going to bite you back if you don't know about it... Julio
[toc] | [prev] | [next] | [standalone]
| From | luserdroog <luser.droog@gmail.com> |
|---|---|
| Date | 2019-11-23 19:52 -0800 |
| Message-ID | <add80328-4845-44c6-b80d-156a8b9197f4@googlegroups.com> |
| In reply to | #37853 |
On Saturday, November 23, 2019 at 9:08:33 PM UTC-6, Julio Di Egidio wrote: > On Sunday, 24 November 2019 03:57:05 UTC+1, luserdroog wrote: > > On Saturday, November 23, 2019 at 8:21:10 PM UTC-6, Julio Di Egidio wrote: > > > On Saturday, 23 November 2019 21:09:31 UTC+1, luserdroog wrote: > > > > On Friday, November 22, 2019 at 1:11:14 PM UTC-6, Jonas Thörnvall wrote: > > > > > > > > > I probably should learn use JSON maybe next project. > > > > > > > > I think it is a very good idea to learn to use JSON, but there's no > > > > need to wait! You probably already know the details, you just don't > > > > know that you know. > > > > > > > > JSON stands for JavaScript Object Notation. It's just the normal > > > > syntax for describing data that you already use everywhere in > > > > JavaScript. The only difference is that it is embedded or serialized > > > > in strings, or stored in a file. > > > > > > That is not true: there are some differences between JSON and JS proper, > > > and they are going to bite you back at the first non-trivial application > > > if you aren't aware of them... > > > > With all due respect, that's just FUD. I may well be ignoring some > > details. But OP already has JSON data produced by the library he's > > using. That's half of the equation already done. Finito. > > > > Using JSON.parse() to interpret that data would already > > have saved the several days work he's already invested in writing > > lots of fiddly code to parse it. Starting to use it now, even if > > difficulties arise (which he will likely post about and receive > > help with) the will be orders of magnitude less effort than continuing > > down the current path. > > I have not said JSON is not the way to go, that's fine: I just said be careful > with it (aka, look up the details in the documentation, sooner or later) for it > is *not* just JS syntax, and it *is* going to bite you back if you don't know > about it... > That I can agree with. I think you're right. Sorry to get so defensive. :) droog
[toc] | [prev] | [next] | [standalone]
| From | Julio Di Egidio <julio@diegidio.name> |
|---|---|
| Date | 2019-11-23 21:54 -0800 |
| Message-ID | <d4396283-4db2-4bef-a681-1796d7ed2824@googlegroups.com> |
| In reply to | #37855 |
On Sunday, 24 November 2019 04:52:30 UTC+1, luserdroog wrote: > On Saturday, November 23, 2019 at 9:08:33 PM UTC-6, Julio Di Egidio wrote: > > On Sunday, 24 November 2019 03:57:05 UTC+1, luserdroog wrote: > > > On Saturday, November 23, 2019 at 8:21:10 PM UTC-6, Julio Di Egidio wrote: > > > > On Saturday, 23 November 2019 21:09:31 UTC+1, luserdroog wrote: > > > > > On Friday, November 22, 2019 at 1:11:14 PM UTC-6, Jonas Thörnvall wrote: > > > > > > > > > > > I probably should learn use JSON maybe next project. > > > > > > > > > > I think it is a very good idea to learn to use JSON, but there's no > > > > > need to wait! You probably already know the details, you just don't > > > > > know that you know. > > > > > > > > > > JSON stands for JavaScript Object Notation. It's just the normal > > > > > syntax for describing data that you already use everywhere in > > > > > JavaScript. The only difference is that it is embedded or serialized > > > > > in strings, or stored in a file. > > > > > > > > That is not true: there are some differences between JSON and JS proper, > > > > and they are going to bite you back at the first non-trivial application > > > > if you aren't aware of them... > > > > > > With all due respect, that's just FUD. I may well be ignoring some > > > details. But OP already has JSON data produced by the library he's > > > using. That's half of the equation already done. Finito. > > > > > > Using JSON.parse() to interpret that data would already > > > have saved the several days work he's already invested in writing > > > lots of fiddly code to parse it. Starting to use it now, even if > > > difficulties arise (which he will likely post about and receive > > > help with) the will be orders of magnitude less effort than continuing > > > down the current path. > > > > I have not said JSON is not the way to go, that's fine: I just said be careful > > with it (aka, look up the details in the documentation, sooner or later) for it > > is *not* just JS syntax, and it *is* going to bite you back if you don't know > > about it... > > That I can agree with. I think you're right. Sorry to get so > defensive. :) Thanks for the acknowledgement and no worries... Julio
[toc] | [prev] | [next] | [standalone]
| From | luserdroog <luser.droog@gmail.com> |
|---|---|
| Date | 2019-11-23 18:56 -0800 |
| Message-ID | <077d123e-2d28-4ff2-94f8-b832ee2818aa@googlegroups.com> |
| In reply to | #37852 |
On Saturday, November 23, 2019 at 8:21:10 PM UTC-6, Julio Di Egidio wrote: > On Saturday, 23 November 2019 21:09:31 UTC+1, luserdroog wrote: > > On Friday, November 22, 2019 at 1:11:14 PM UTC-6, Jonas Thörnvall wrote: > > > > > I probably should learn use JSON maybe next project. > > > > I think it is a very good idea to learn to use JSON, but there's no > > need to wait! You probably already know the details, you just don't > > know that you know. > > > > JSON stands for JavaScript Object Notation. It's just the normal > > syntax for describing data that you already use everywhere in > > JavaScript. The only difference is that it is embedded or serialized > > in strings, or stored in a file. > > That is not true: there are some differences between JSON and JS proper, > and they are going to bite you back at the first non-trivial application > if you aren't aware of them... > With all due respect, that's just FUD. I may well be ignoring some details. But OP already has JSON data produced by the library he's using. That's half of the equation already done. Finito. Using JSON.parse() to interpret that data would already have saved the several days work he's already invested in writing lots of fiddly code to parse it. Starting to use it now, even if difficulties arise (which he will likely post about and receive help with) the will be orders of magnitude less effort than continuing down the current path.
[toc] | [prev] | [standalone]
Page 2 of 2 — ← Prev page 1 [2]
Back to top | Article view | comp.lang.javascript
csiph-web