2008 May 30 10:38 AM
Hi,
I am trying to
parse a string and escape (\) everything that's not a letter.
How can it be done ?
e.g.
User enters w+
His input ( through select-options )
w+ must be escaped as w\+
data lv_string(20) type c.
select-options s_input for lv_string.
DATA: moff TYPE i,
mlen TYPE i,
s type string.
translate s_input-low TO LOWER CASE.
FIND REGEX s_input-low IN 'xcdfedfrfv'
MATCH OFFSET moff
MATCH LENGTH mlen.
2008 May 30 10:57 AM
Hi,
try this:
REPORT test.
CONSTANTS:
maxstrlen TYPE i VALUE 10.
PARAMETER x(maxstrlen) LOWER CASE.
DATA:
off TYPE i,
off_y TYPE i,
len TYPE i,
y LIKE x.
len = STRLEN( x ).
WHILE ( off < len ) AND ( off_y < maxstrlen ).
IF NOT ( ( xoff(1) >= 'a' AND xoff(1) <= 'z' ) OR
( xoff(1) >= 'A' AND xoff(1) <= 'Z' ) ).
y+off_y(1) = '\'.
off_y = off_y + 1.
ENDIF.
IF off_y < maxstrlen.
yoff_y(1) = xoff(1).
ENDIF.
off = off + 1.
off_y = off_y + 1.
ENDWHILE.
x = y.
WRITE x.
regards
Walter Habich
Hi,
I am trying to
parse a string and escape (\) everything that's not a letter.
How can it be done ?
e.g.
User enters w+
His input ( through select-options )
w+ must be escaped as w\+
data lv_string(20) type c.
select-options s_input for lv_string.
DATA: moff TYPE i,
mlen TYPE i,
s type string.
translate s_input-low TO LOWER CASE.
FIND REGEX s_input-low IN 'xcdfedfrfv'
MATCH OFFSET moff
MATCH LENGTH mlen.
2008 May 30 10:57 AM
Hi,
try this:
REPORT test.
CONSTANTS:
maxstrlen TYPE i VALUE 10.
PARAMETER x(maxstrlen) LOWER CASE.
DATA:
off TYPE i,
off_y TYPE i,
len TYPE i,
y LIKE x.
len = STRLEN( x ).
WHILE ( off < len ) AND ( off_y < maxstrlen ).
IF NOT ( ( xoff(1) >= 'a' AND xoff(1) <= 'z' ) OR
( xoff(1) >= 'A' AND xoff(1) <= 'Z' ) ).
y+off_y(1) = '\'.
off_y = off_y + 1.
ENDIF.
IF off_y < maxstrlen.
yoff_y(1) = xoff(1).
ENDIF.
off = off + 1.
off_y = off_y + 1.
ENDWHILE.
x = y.
WRITE x.
regards
Walter Habich
2008 May 30 11:00 AM
hi check this..
data lv_string(20) type c.
select-options s_input for lv_string.
DATA: moff TYPE i,
mlen TYPE i,
s type string.
translate s_input-low TO LOWER CASE.
replace all occurrences of 'w' in s_input-low with 'w/' .
regards,
venkat
2008 May 30 11:02 AM
or have a look at CL_ABAP_REGEX and the parameter SIMPLE_REGEX:
DATA: regex TYPE REF TO cl_abap_regex,
moff TYPE i,
mlen TYPE i,
text TYPE string.
text = 'xcdfedf+rfv'.
CREATE OBJECT regex
EXPORTING
pattern = 'f+'
simple_regex = 'X'.
FIND REGEX regex IN text
MATCH OFFSET moff
MATCH LENGTH mlen.
write: moff, mlen.
| User | Count |
|---|---|
| 3 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |