‎2007 Oct 22 12:15 PM
Hi,
I need to <b>EXTRACT</b> YYYY in the string <u><</u>XX<u>></u>YYYY<u><u><u><\></u></u></u>
However, only the charachters underlined are constant, as in... <\> will be present at the end of the string, but the first <> can have varying data between it.
string examples:
<u><</u>PQRST<u>></u> YYYY <u><\></u>
<u><</u>ABC<u>></u> XXXXYYYY <u><\></u>
I need to extract the 'YYYY' or 'XXXXYYYY' or whatever else that comes after the closure of the first bracket '<*>' and the start of the second bracket '<\>'.
I tried sy-fdpos, but it only gives the START of the <*> part. What really helps me is the CLOSE of the first <> and START of the second <>.
Thanks in advance.
‎2007 Oct 22 1:20 PM
You can also use this:
while lv_string(1) ne '>'.
shift lv_string.
endwhile.
shift lv_string.
if lv_string CA '<'.
lv_result = lv_string(sy-fdpos).
endif.
lv_result will contain the values between the first > and the second <.
Regards,
Michael
‎2007 Oct 22 12:57 PM
Hi,
You can split at each ">" and delete the 2 last caracters of the second data.
example :
<test>YYYY<\>
first data : <test
second data : YYYY<\ -> YYYY
‎2007 Oct 22 1:06 PM
‎2007 Oct 22 1:20 PM
You can also use this:
while lv_string(1) ne '>'.
shift lv_string.
endwhile.
shift lv_string.
if lv_string CA '<'.
lv_result = lv_string(sy-fdpos).
endif.
lv_result will contain the values between the first > and the second <.
Regards,
Michael
‎2007 Oct 22 2:00 PM
Thanks a bunch for your replies mates,
Absolute peach of a logic there by Michael, was best suited for my smartform. That's the one I used.
All rewarded
‎2007 Oct 22 1:43 PM
Hi
<XX>YYYY<\>, as you told in this string </> will be in the last.
data: a type i,
str = <XX>YYYY<\> ." (string)
a = strlen( str ).
a = a - 7. " as last is </> -
3 chars plus YYYY --- 4 chars. so 7 chars
shift str left by a places.
if it doesn't work,
do a times.
shift str left.
enddo.
now you will get str = YYYY</>.
now ,
str = str(4). " finally you will get str = YYYY.
‎2007 Oct 22 1:44 PM
Regular expressions are the best way of doing that:
REPORT zregex.
DATA:
tmp(20) TYPE c,
pattern(50) TYPE c,
s1(10) TYPE c,
s2(10) TYPE c,
s3(10) TYPE c,
s4(10) TYPE c,
s5(10) TYPE c,
n TYPE i,
it_result TYPE match_result_tab.
tmp = '<ABC> XXXXYYYY <>'.
pattern = '.*(<.*>)(.*)(<>).*'.
FIND REGEX pattern
IN tmp
MATCH COUNT n
RESULTS it_result
SUBMATCHES s1 s2 s3 s4 s5.
write:/ s1, s2, s3.
Message was edited by:
Rainer Hübenthal