[Date Prev][Date Next][Subject Prev][Subject Next][ Date Index][ Subject Index]

Re: XPL question: offset into a string?



** Reply to note from charles.herold@xxxxxxxx 01/08/96 11:15pm GMT

> Is there any way of pulling a substring from a string in XPL by an
> offset, rather than using the XS command. That is, if I have the string
> "hello there", could I get the "there" into it's own variable just by
> knowing that the 't' is offset in by 7 characters? In this particular
> case I could use XS to divide the string into what is before and after
> the space, but I want to do something far more involved (which I won't
> waste your time with). Basically I want the equivalant of Basic's MID$.

 The following returns RIGHT$ rather than MID$,
  but that's what your example requires, because
  you don't specify length of MID$
 Suggest you experiment with different offsets (change S/G 02);
  notice what happens if S/G02 <1 or >10
 Not really bulletproof: ALL characters in source string
  MUST be 1-byte chars, otherwise this solution bombs.
  If you suspect presence of 2- or 3-byte chars in source$,
  then you must proceed differently (probable strategy would be
  to strip characters one-by-one off the left end of the string,
  then test for length>1)


XPLeNCODE v1.8
b-gin RIGHTSTR.PM
[cr|lf]
{<}SV01,hello_there{>};*; source$[cr|lf]
{<}SX02,6{>};*; offset=6 (not 7!)[cr|lf]
{<}IF{<}VA|01{>}<={<}PV02{>}{>}{<}PROffset
 exceeds length of source$ - Abort{>}{<}EX{>}{<}EI{>};*;[cr|lf]
{<}SX03,{<}IS01{>}{>}{<}IF{<}PV02{>}>0{>}{<}SX04,0{>}
{<}SV05,{>};*;[cr|lf]
{<}LBA{>}{<}IF{<}PV02{>}>{<}PV04{>}{>}{<}SX04,{<}PV04{>}+1{>}
{<}SX05,{<}IS05{>}+"{27}X"{>}{<}GLA{>}{
<}EI{>};*;[cr|lf]
{<}XS01,05,,02,03{>}{<}EI{>}{<}PR@03{>}{<}EX{>}
-nd
XPLeNCODE


-----------
Robert Holmgren
holmgren@xxxxxxxx
-----------