Page 1 of 1

pgSplitToArray

PostPosted: Fri Oct 27, 2023 1:34 pm
by John Robin Dove
Hi Clifton,
I think I may have found a problem in this function but, on the other hand, I may be asking too much of it.
I often use the $ character like this: var secs = 25; var txt = 'You will have $ seconds to do this task.'; txt = tbfunction_pgReplace('$', '$', txt); result: You will have 25 seconds to do this task. No problem.

I tried to use pgSplitToArray on a sentence like that and it would seem to be dysfunctional. Try this:
var txt = "How are you $ doing today?';
var myArray = txt.split("$");
alert (myArray[0] + "\n" + myArray[1]);

result:
How are you
doing today?

var myArray2 = tbfunction_pgSplitToArray("$", txt)
alert (myArray2[0] + "\n" + myArray2[1]);

result:
$
undefined


I then tried this:
var txt = "How are you and how are doing today?';
var myArray == tbfunction_pgSplitToArray("and", txt)
alert (myArray[0] + "\n" + myArray[1]);

result:
and
undefined


It's not a problem for me and maybe I'm missing someting obvious but you might want to take a look at it.

John

Re: pgSplitToArray

PostPosted: Fri Oct 27, 2023 1:38 pm
by Clifton
Hi John,
I will take a look.
Seems like a bug to me and it should be fixed.
Clifton

Re: pgSplitToArray

PostPosted: Fri Oct 27, 2023 2:04 pm
by Clifton
Hi John,

The function seems to work in your scenarios if you switch your parameters.
tbfunction_pgSplitToArray( txt, "$" );


Seems to work. The API help indicates the string to manipulate must come first in the function call.
Sometimes, when you just want to test some code, you can use this page to do it.
https://pgsoftwaretools.com/powerpac/assessments/exec-js/fe/index.html
I use it a lot for little snippets. Every so often I update the page to use the latest PowerPac release.

Clifton

Re: pgSplitToArray

PostPosted: Fri Oct 27, 2023 4:23 pm
by John Robin Dove
Thanks. So I was doing it back to front. Sorry, I should have read the instructions more carefully. I've used the function correctly hundreds of times before. I don't why I decided to change the order. As I suspected, the explanation was obvious but I didn't spot it.