scripting strings

Discuss problems and solutions.
oldgearguy
Regular
Posts: 315
Joined: 02 Nov 2013 11:19

Re: scripting strings

Post by oldgearguy »

I had a second method, but I really need to key it into the editor and see if it runs.
The basic idea is to turn a number into a string, then subarray it:

strNum = ''+num; // concatenating a null string to a number turns it into a string
answer = subarray(strNum, 0, sizeof(strNum) - 3);

Given that subarray() and sizeof() work on arrays and not strings, this idea might need tweaking...
Softcore
Regular
Posts: 1613
Joined: 04 Nov 2012 08:34

Re: scripting strings

Post by Softcore »

Just checked this last one because if it worked it would be a great revelation.......

But it didnt lol! Obviously subarray doesnt work on strings
Softcore
Regular
Posts: 1613
Joined: 04 Nov 2012 08:34

Re: scripting strings

Post by Softcore »

There are of course a lot of ways to create a script but it all depends on what exactly is the expected range of our value....that 1.38974934 got me wondering (seeing > 1)
oldgearguy
Regular
Posts: 315
Joined: 02 Nov 2013 11:19

Re: scripting strings

Post by oldgearguy »

Softcore wrote:There are of course a lot of ways to create a script but it all depends on what exactly is the expected range of our value....that 1.38974934 got me wondering (seeing > 1)
I think my script will handle any possible numeric value. That's why I treated the whole number part and fractional part separately and then glued them back together around the decimal point at the end.
Softcore
Regular
Posts: 1613
Joined: 04 Nov 2012 08:34

Re: scripting strings

Post by Softcore »

Oh yes, your first one, most definitely - I was thinking something along your second approach......

I'll check it out in a Lemur template and report back! ;)
Softcore
Regular
Posts: 1613
Joined: 04 Nov 2012 08:34

Re: scripting strings

Post by Softcore »

OK, I can confirm the first solution of Oldgearguy works with a slight change in the manual script....

See....this one is NOT converted into a string:

Code: Select all

answer = num+'.'+frac;
THIS ONE though is:

Code: Select all

answer =''+ num+'.'+frac;
(for some reason, Lemur string concatenation assumes a summed variable to be a string, only when the first element of the concatenation is a string)

And here is an example
Attachments
oldgear-fraction.jzml
(2.99 KiB) Downloaded 65 times
oldgearguy
Regular
Posts: 315
Joined: 02 Nov 2013 11:19

Re: scripting strings

Post by oldgearguy »

Softcore wrote:OK, I can confirm the first solution of Oldgearguy works with a slight change in the manual script....

See....this one is NOT converted into a string:

Code: Select all

answer = num+'.'+frac;
THIS ONE though is:

Code: Select all

answer =''+ num+'.'+frac;
(for some reason, Lemur string concatenation assumes a summed variable to be a string, only when the first element of the concatenation is a string)

And here is an example
Thanks for checking and correcting. Funny -- I had written it the first way initially then deleted it thinking I had done string cats before without the first part being a string.
I haven't been home much and can't install/run the Lemur editor at work, so I appreciate you taking the time to punch it in and fix it.
Softcore
Regular
Posts: 1613
Joined: 04 Nov 2012 08:34

Re: scripting strings

Post by Softcore »

No worries!

On the (ironic) contrary, after some stupid false procedures of telecommunication companies, Im left with no internet connection at home, possibly for the next 10 - 15 days too. Thank God there's internet and a few spare moments at my workplace. Of course laptop at work also has Lemur editor installed ;)
Post Reply