Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

cascade special characters

Former Member
0 Likes
627

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.

1 ACCEPTED SOLUTION
Read only

former_member435013
Active Participant
0 Likes
589

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.

3 REPLIES 3
Read only

former_member435013
Active Participant
0 Likes
590

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

Read only

Former Member
0 Likes
589

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

Read only

karsten_korte
Participant
0 Likes
589

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.