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

Replace

Former Member
0 Likes
761

Hi everybody.

I have to do a replace using a regular expression to do this:

For example in a XML string, clear al the occurrences of the string like this:

I want to delete all this occurrence.

<field>0000-00-00</field>

I employ a replace like this:

DATA: reg_exp type string.

reg_exp = '<>0000-00-00</>'.

REPLACE ALL OCURRENCES OF REGEX reg_exp IN XML_STRING with ''.

It return me a sy-subrc = 4.

I don't know how to delete all this substring, or witch reg_exp pattern should i employ.

Anybody can help me??

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
742

replace them with SPACE or ' '. not ''.

AFTER that do:

condense XML_STRING.

5 REPLIES 5
Read only

Former Member
0 Likes
743

replace them with SPACE or ' '. not ''.

AFTER that do:

condense XML_STRING.

Read only

Former Member
0 Likes
742

HI,

Write like this

REPLACE ALL OCURRENCES OF reg_exp IN XML_STRING with SPACE.

Regards

Sudheer

Read only

0 Likes
742

No. I wanna know if my regex is ok.

Please, could you check if my search pattern is correct?????'???

Read only

Former Member
0 Likes
742

but is built ok my reg_exp???

Read only

Former Member
0 Likes
742

Hi Miguel,

Look at this sample code with output.

DATA: T(10) VALUE 'abcdefghij',

STRING LIKE T,

STR1(4) VALUE 'cdef',

STR2(4) VALUE 'klmn',

STR3(2) VALUE 'kl',

STR4(6) VALUE 'klmnop',

LEN TYPE I VALUE 2.

STRING = T.

WRITE STRING.

REPLACE STR1 WITH STR2 INTO STRING.

WRITE / STRING.

STRING = T.

REPLACE STR1 WITH STR2 INTO STRING LENGTH LEN.

WRITE / STRING.

STRING = T.

REPLACE STR1 WITH STR3 INTO STRING.

WRITE / STRING.

STRING = T.

REPLACE STR1 WITH STR4 INTO STRING.

WRITE / STRING.

The output appears as follows:

abcdefghij

abklmnghij

abklmnefgh

abklghij

abklmnopgh

Note how, in the last line, the field STRING is truncated on the right. The search pattern 'cdef' of length 4 is replaced by 'klmnop' of length 6. Then, the rest of the field STRING is filled up to the end of the field.

<b>Reward points, if helpful.</b>

Regards,

Atin