pgSplitToArray

Workarounds and usability notes.

pgSplitToArray

Postby John Robin Dove » Fri Oct 27, 2023 1:34 pm

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
John Robin Dove
 
Posts: 486
Joined: Thu Jan 23, 2014 4:35 am

Re: pgSplitToArray

Postby Clifton » Fri Oct 27, 2023 1:38 pm

Hi John,
I will take a look.
Seems like a bug to me and it should be fixed.
Clifton
Clifton
Site Admin
 
Posts: 732
Joined: Tue Jan 14, 2014 1:04 am

Re: pgSplitToArray

Postby Clifton » Fri Oct 27, 2023 2:04 pm

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
Clifton
Site Admin
 
Posts: 732
Joined: Tue Jan 14, 2014 1:04 am

Re: pgSplitToArray

Postby John Robin Dove » Fri Oct 27, 2023 4:23 pm

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.
John Robin Dove
 
Posts: 486
Joined: Thu Jan 23, 2014 4:35 am


Return to General Discussion

Who is online

Users browsing this forum: No registered users and 4 guests

cron