Page 1 of 1

Quetions on gettoken and strpos.

Posted: 03 May 2012 03:04
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";

Re: Quetions on gettoken and strpos.

Posted: 03 May 2012 11:09
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).

Re: Quetions on gettoken and strpos.

Posted: 04 May 2012 17:45
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.