[Date Prev][Date Next][Thread Prev][Thread Next]
[Author Index] [Date Index] [Thread Index]
[SQR-USERS Info] [SQRUG Home Page]

Re: SQR instr()



I don't know of a built in function to do this.  The quickest thing to do
would be to write a procedure to do it.  Unless you know C and are able to
link a modified UFUNC.C back into SQR as described in the help file at the
end of the LET command help.  I have not done this.

The procedure in SQR might go something like this. #M_pos should have the
starting position of the last occurance of $srch_str in $in_str.

This has not been tested.  Hope it helps.

do INSTR_BACK "Today M is M Friday", "M", #M_pos

begin-PROCEDURE INSTR_BACK $in_str, $srch_str, :#pos

  let #in_size = length($in_str)
  let #srch_size = length($srch_str)
  move 0 to #pos

  let #srch_pos = #in_size + 1 - #srch_size

  while #srch_pos > 0

    let $chk_str = substr($in_str, #srch_pos, #srch_size)

    if $chk_str = $srch_str
      move #srch_pos to #pos
      break
    end-if

    let #srch_pos = #srch_pos - 1

  end-while

end-PROCEDURE

> Hi Guys,
>
> I need same functionality as INSTR() function,
> BUT with one more added functionality which can give
> me a position for a sub_value from end of the source_value.
>
> Say for eg: $source = 'Today M is M Friday.'
> I want instr() to give me a position of 'M' just before 'Friday'.
>
> Is there any simple solution. I tried giving negative offset
> thinking it will start searching from end. No luck.
>
> I can achive doing some more coding. Is there any real
> easy solution, which can save me extra coding.
>
>
> FROM MANUAL:
> INSTR
> Returns the numeric position of sub_value in source_value or zero (0) if
not
> found.  The search begins at offset offset_value.  This function returns a
> float value.
>
> Syntax: dst_var =       instr(source_value, sub_value, offset_value)
>
>
> Thanks in advance,
> Manoj
>
> ______________________________________________________
> Get Your Private, Free Email at http://www.hotmail.com