my first Javascript - parseint :)

Questions and discussion about building and using Max for Live devices
Post Reply
flowdesigner
Posts: 930
Joined: Sun Dec 21, 2008 5:58 am

my first Javascript - parseint :)

Post by flowdesigner » Thu Nov 25, 2010 1:55 pm

Hi,

I guess that would be easy. I want to send an integer embedded inquotes into a js, remove the quotes, like fromsymbol, and and output an integer.
What would this look like?

Thanks

pid
Posts: 354
Joined: Thu Nov 05, 2009 9:51 am

Re: my first Javascript - parseint :)

Post by pid » Thu Nov 25, 2010 2:27 pm

sorry i couldn't resist

<pre><code>
----------begin_max5_patcher----------
758.3oc0Xt0aaBCEG+YxmBjeNqBeiK6s84XoZhj3lxTvDANZ8h528EeLVwMi
TLAxZ5CkiNFp4u+w4hcdcV.ZY0ShFT32C+YXPvqyBBfgzCDz5GfJyeZ017F3
wPK2qTURzbysJVCCVs72eiDYGbWsnQHU4phJ4upEqTl4mg42EMOjfwZST6kv
6a+uj6KKjaEJ30fsSUtZ0iExMcLMQDiwd0chp1qNclLCoddmvLMnk4xMnv60
28sYyzWl6IBjh+bXAaWsJwSfxPurMbqnKxfyrC9PkTIyKAIf9QcQ9VTWqdxG
r5y.5QwwfIqmUOw4E2T7B7hwZvcFnfle3uoDJpvCToKljNPl3QDQLvjL1c7a
albHPYSc09ccgkjILTwfEJiBXgeyDpTJZZx2H9GtzHTcgDVO0UnTSk.Nsy5J
iGjjzHCHM4bDc7ENs2JNdCxo.ht.i6IvRRtx.KALXNCLe1D6LYiOTWU17b4x
pNKSE2GKignNBIaLrr+hasE7Snd1t6SAkEJQcWPjN805MsAII2D33bEzVfXj
EnvEHRFXRS.SBCLXV5BTW3hzWLGK0jWEckxesPlA0Ivrnah72ytySLdnQQXS
o7jrOqsPNrVfS39GwlOs3T1WhdYI81Jy7widsZkgsm1.R43QeY6jEOc0fayd
vwQ2Psj93Zvc.D5DlT0BDb1+gjJXRQaKjmdtcPX5weOkZp1WuxNU1CpGdTaq
EMpBIjX47P5lPNOziEqWKf6aUYYw5cUERUqHXDywtnXsw06LeM8Us5MOzuZi
uH0RwPrqq2XUKwG0ldYrMl3xVs2XUapOpkdYpMM0gsf2TnVbepMaXpkGYNpx
ACeN3wa8FqZy7gsIuaI4kZ05y76935MV0l3iZ4CSs17JyuKiq2XUarur8BpI
XXqq2XUKyW1N.0RRyrzDRuN5MV0h8PsCrj.lygVhG1Dk133MRw5SN1.CCvsE
rh.iq2H0ZrmZEObtlQc4p1ajZ0mdtwWVLf8rqG8NY2Myda1eA.ttP1F
-----------end_max5_patcher-----------
</code></pre>

i guess there would be an advantage to js if you were doing something else with these numbers in quotes...
3dot... wrote: in short.. we live in disappointing times..

Gravis
Posts: 104
Joined: Sat Jul 28, 2007 4:47 am

Re: my first Javascript - parseint :)

Post by Gravis » Fri Nov 26, 2010 1:01 pm

I have this exact solution in my JS code :)

Will post it for you in a day or two when i get home
iMac G5 2.16 | Echo AudioFire12 | Xone 92 | Live 8 + M4L | Trigger Finger | Monome 256 | Kenton Killamix Mini | Truth 3031A

Gravis
Posts: 104
Joined: Sat Jul 28, 2007 4:47 am

Re: my first Javascript - parseint :)

Post by Gravis » Tue Nov 30, 2010 11:36 pm

Code: Select all

blah = parseInt(StringToParse, 10);
This will ensure any string you pass into the method will be returned with base 10 which is what you want.

You may also want to strip the " " from a number(i think that might be the problem you are talking about)

Code: Select all

// remove the first "
myString = myString.substring(1, myString.length);

// remove the trailing "
myString = myString.substring(0, myString.length-1);
Does that make sense?
iMac G5 2.16 | Echo AudioFire12 | Xone 92 | Live 8 + M4L | Trigger Finger | Monome 256 | Kenton Killamix Mini | Truth 3031A

flowdesigner
Posts: 930
Joined: Sun Dec 21, 2008 5:58 am

Re: my first Javascript - parseint :)

Post by flowdesigner » Wed Dec 01, 2010 8:05 pm

thanks man, I check it out when I come home

fxcoaching
Posts: 3
Joined: Wed Dec 01, 2010 7:49 am

Re: my first Javascript - parseint :)

Post by fxcoaching » Thu Dec 02, 2010 5:49 am

Gravis wrote:

Code: Select all

blah = parseInt(StringToParse, 10);
This will ensure any string you pass into the method will be returned with base 10 which is what you want.

You may also want to strip the " " from a number(i think that might be the problem you are talking about)

Code: Select all

// remove the first "
myString = myString.substring(1, myString.length);

// remove the trailing "
myString = myString.substring(0, myString.length-1);
Does that make sense?

this is correct

Post Reply