Sunday, August 12, 2007

QM Quickling: FIND

_i= find(a "5")

This topic has hit the forums a lot lately and so I decided to do a little something on it.

'Find' is one of those funny little functions that returns a number instead of assigning it's value to a string like 'findreplace', 'left', etc. What it's doing is giving you the position of the first character of the sub-string that it finds. Here's an example right out of the Help document (press F1 and surf in there for a while it's really well done).

str s = "Notepad.exe"
int i = find(s ".exe")
out i;; now i is 7


Things to remember:

  • it is zero indexed so you need to remember that the first character is in position 0 not 1.
  • because it is zero indexed, the position returned for the last character will be 1 less than the length of the string.
  • if there is more than one line, the "newline" character in the Windows world is actually 2 characters. Here's an example of that:
    • int z
      str a=
      ;1
      ;2
      ;3
      ;4
      ;5

      z=len(a)
      _i= find(a "3")
      out z
      out _i

Find is useful even if you don't care where in the source-string the string lies. For example, if you just want to know that it is in there somewhere, just test to see if the number returned is greater than '-1' which is what is returned if it is not present.

Ok, so now you have 5 days to put this into your code and learn the Feng shui of 'find'.

No comments: