Loading ...
Sorry, an error occurred while loading the content.

Re: Index number of array element

Expand Messages
  • ebbtidalflats
    Hi Flo, Yes, you need an extra delimiter. However, I would NOT place it at the end of the array. That would require you to structure the array with this
    Message 1 of 16 , Feb 5, 2009
    • 0 Attachment
      Hi Flo,

      Yes, you need an extra delimiter. However, I would NOT place it at the
      end of the array. That would require you to structure the array with
      this particular code in mind, rather than make to index code work with
      ANY array.

      If you place the extra delimiter at the end of the array within the
      string position test, it will always be there, whether the array has a
      trailing delimiter or not. Extracting the StrPos function from your
      codeline (and adding quotes):

      ^$StrPos("|^%name%|";"|^%Array%|";1)$

      would parse as either (without trailing delimiter in array:

      ^$StrPos("|Flo|";"|Anthony|Bertha|Bert|Carla|David|Eb|Flo|";1)$

      or WITH trailing delimiter in the array:

      ^$StrPos("|Flo|";"|Anthony|Bertha|Bert|Carla|David|Eb|Flo||";1)$

      Then, when you count delimiters, you can drop the trailing delimiters:

      ; the whole long line start
      ^!Set
      %Index%=^$StrCount("|";"^$StrCopyLeft("|^%Array%";^$StrPos("|^%Name%|";"|^%Array%|";1)$)$";0;1)$
      ; long line end



      Cheers,


      Eb

      --- In ntb-clips@yahoogroups.com, "Flo" <flo.gehrke@...> wrote:
      >
      > Thanks for these corrections, Eb! It's clear to see why the trailing
      > delimiter is needed. Without that delimiter, "Bert",
      > in "Anthony|Bertha|Bert|Carla|David|Eb|Flo", is counted as #2. The
      > solution is just another "|" in line #4 after ^%Name%.
      >
      > On this condition, however, we need another delimiter at the end of
      > the array. Without this delimiter, "Flo" would be counted as "0".
      > (Normally, a delimiter without a following value could cause some
      > trouble but, in this case, it doesn't matter.)
      >
      > In my tests, this works fine...
      >
      > ^!SetListDelimiter |
      > ^!SetArray %Array%=Anthony|Bertha|Bert|Carla|David|Eb|Flo|
      > ^!Set %Name%=^?{(T=L)Select a name==^%Array%}
      > ; long line start
      > ^!Set %Index%=^$StrCount(|;^$StrCopyLeft(|^%Array%;^$StrPos(|^%Name%
      > |;|^%Array%;1)$)$;0;1)$
      > ; long line end
      > ^!Info ^%Name% is number ^%Index%
      >
    Your message has been successfully submitted and would be delivered to recipients shortly.