[Date Prev][Date Next][Thread Prev][Thread Next]
[Author Index]
[Date Index]
[Thread Index]
[SQR-USERS Info]
[SQRUG Home Page]
Re: SQR instr()
- Subject: Re: SQR instr()
- From: Cherno Jagne <ITSCJ@QE2-HSC.NS.CA>
- Date: Tue, 9 Nov 1999 17:05:56 -0400
There is indeed a real easy solution which can save
you extra coding:
let #pos = instr(edit($source,'R'),' ',0)
The edit format mask 'R' reverses the source string and
voila! the result is as if instr() started from the end of the string.
Of course if you wanted this position from the START of
the source string you would do:
let #pos = length($source) - instr(edit($source,'R'),' ',0) + 1
Both of these are just special cases--when the substring
is just one character. In general:
let #pos = instr(edit($source_str,'R'),edit($sub_str,'R'),0) +
length($sub_str) - 1
let #pos = length($source_str) -
instr(edit($source_str,'R'),edit($sub_str,'R'),0) - length($sub_str) + 2
Watch for exceptional cases, eg. when the $sub_str is not found within
source_str, etc.
Hope that helped,
Cherno Jagne
Programmer/Analyst
QEII Health Sciences Centre
Halifax
N.S. Canada
>>> Manoj Gurjar <mgurjar@HOTMAIL.COM> 11/05 1:00 PM >>>
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