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

22620Re: StrPos returns -1 in V7pr5 instead of 0

Expand Messages
  • Eb
    Apr 19, 2012
    • 0 Attachment
      I just happen to be looking at the same topic. The description in the WhatsNew file isn't exactly accurate.

      1. all the old syntaxes still work.
      2. The options are NOT optional. You must use either the old or the new options.

      I haven't tried the regexp and wildcard versions yet, but a simple example follows:

      First select some text containing spaces, then run the following clip code:

      ^!Set %count%=^$StrCount("^%SPACE%";"^$GetSelection$";I)$
      ^!Set %pos%=^$StrPos("^%SPACE%";"^$GetSelection$";I)$
      ^!Set %repl%=^$StrReplace("^%SPACE%";"'|'";"^$GetSelection$";IA)$
      ;long line follows
      ^!Info [L]Count^%tab%^%count%^%nl%Posit^%tab%^%pos%^%nl%Replc^%tab%^%repl%

      Note the third line, which tell you that you can have more than one of these options set, very much like the Find or Replace commands.


      Cheers,


      Eb

      --- In ntb-clips@yahoogroups.com, "joy8388608" <mycroftj@...> wrote:
      >
      > Can someone give me an example of the new syntax for StrPos?
      > Would it be ^$StrPos("x";"wxyz";I)$ ?
      >
      > If so, what about the older syntax ^$StrPos("SubStr";"Str";CaseSensitive)$ ?
      >
      > I just noticed StrPos returned 0 if no match in V6 but returns -1 if no match in V7pr5 when using the V6 syntax. Intentional? If so, why? This is going to break a few clips.
      >
      > ; Examine entire document text and look for the first TAB
      > ^!Prompt StrPos returns ^$StrPos("^%TAB%";"^$GetText$";False)$
      >
      > ^$StrCount("SubStr";"Str"[;Options])$
      > ^$StrPos("SubStr";"Str"[;Options])$
      > ^$StrReplace("SubStr";"ReplaceStr";"Str";Options)$
      >
      > Options:
      > C: Searches for whole words only.
      > I: Ignores character case.
      > R: Specifies that the search criteria represents a regular expression
      > *: Specifies that the search criteria uses wildcards.
      > A: Use to replace all matched occurrences with ^$StrReplace. When this option is not used, only the first match is replaced.
      >
      > Joy
      >
    • Show all 4 messages in this topic