Quetions on gettoken and strpos.

Please check the FAQ (https://www.xyplorer.com/faq.php) before posting a question...
Post Reply
neutrox
Posts: 194
Joined: 05 Mar 2012 15:23

Quetions on gettoken and strpos.

Post by neutrox »

a. How do I get the first and the last strings' position using sc stringpos, if a string occurs in a sequence?

b. How can I get entire blocks of repeated strings out of a variable? The following script is an attempt and I need to split those blocks ("1", "2 2", "3 3 3" and so on).

Code: Select all

// step;
   $max = "12";
   $sep = " ";
   $list = "";
   $first= "";
   $loop = 1;

   WHILE ($loop <= $max) {
// step;
                         $play = strrepeat("$loop ", $loop);
                         $first= "$first" . "$play";
                         $loop++;
                          }

   $input = $first;

   $sort = formatlist($input, se, "$sep");
   $sort = "$sep" . "$sort" . "$sep";
   $sort = trim($sort, " ");

      $uni = formatlist($input, sed, "$sep");

   foreach ($tk, $uni, $sep) {
///////////////////////////////////////////////
 step; // step here so you'll see what's needed
///////////////////////////////////////////////
   $cnt = gettoken($sort, count, " $tk ");
   $list = "$list" . "$tk = $cnt<crlf>";

                             }
  text "$list";

Stefan
Posts: 1360
Joined: 18 Nov 2008 21:47
Location: Europe

Re: Quetions on gettoken and strpos.

Post by Stefan »

neutrox wrote:a. How do I get the first and the last strings' position using sc stringpos,
Help > strpos()
start: Negative start positions are supported to begin searching from the start position leftwards.

b. How can I get entire blocks of repeated strings out of a variable?
Don't understand right now (not that much time to get it).

neutrox
Posts: 194
Joined: 05 Mar 2012 15:23

Re: Quetions on gettoken and strpos.

Post by neutrox »

a. completely overlooked the help note on negative start pos. Even tried the 'reverse strings' trick but of course to no avail. So thanks, as

b. no prob, now I have it done.

Post Reply