‎2009 Sep 14 11:16 AM
how to replace multiple new line characters in a line.
Suppose for example my line contains Example1#####Example2##Example3###Example4,
then the output should be Example1#Example2#Example3#Example4.
‎2009 Sep 14 12:21 PM
Hi Sid,
You Can try this code
DATA: ld_string TYPE string,
ld_string1 TYPE string,
ld_string2 TYPE string,
ld_string3 TYPE string.
ld_string = 'Example1#####Example2##Example3###Example4'.
REPLACE ALL OCCURRENCES OF '######' in ld_string with '#'.
REPLACE ALL OCCURRENCES OF '####' in ld_string with '#'.
REPLACE ALL OCCURRENCES OF '###' in ld_string with '#'.
REPLACE ALL OCCURRENCES OF '##' in ld_string with '#'.
write:/1 ld_string.
Regards
Pavan
‎2009 Sep 14 12:42 PM
REPLACE ALL OCCURRENCES OF cl_abap_char_utilites=>new_line in ld_string with ``.
‎2009 Sep 14 12:48 PM
Sorry my first attempt was nonsens.
concatenate CL_ABAP_CHAR_UTILITIES=>newline '+' into pattern.
replace all OCCURRENCES OF regex pattern in s with CL_ABAP_CHAR_UTILITIES=>newline.
‎2009 Sep 14 12:43 PM
Hi Sidhartha,
Please make use the below code to solve your issue.
**************************************************************
DATA: v_line(50) type c value'Example1#####Example2##Example3###Example4',
begin of itab occurs 0,
data(25) type c,
end of itab.
split v_line at '#' into table itab.
clear v_line.
loop at itab where data is not initial.
concatenate v_line itab-data into v_line separated by '#'.
endloop.
if v_line+0(1) = '#'.
v_line+0(1) = ''.
endif.
condense v_line no-gaps.
write : / v_line.
**********************************************************
Hope this will help you.
Regards,
Smart Varghese
‎2009 Sep 14 12:49 PM
Hi Sidhartha,
Try this piece of code -
REPORT sy-repid.
TYPES: BEGIN OF ty_split,
str_lines(255),
END OF ty_split.
DATA: str TYPE string,
itab_split TYPE TABLE OF ty_split,
wa_split TYPE ty_split.
* str contains your input string which has new line characters. you may put the value in that variable as per your logic.
SPLIT str AT cl_abap_char_utilities=>cr_lf INTO TABLE itab_split.
CLEAR str.
LOOP AT itab_split INTO wa_split.
IF sy-tabix EQ 1.
str = wa_split-str_lines.
ELSE.
CONCATENATE str cl_abap_char_utilities=>newline wa_split-str_lines INTO str.
ENDIF.
ENDLOOP.
WRITE str.Hope this helps.
Regards,
Himanshu
‎2009 Sep 15 11:22 AM
Thanks I am able to solve the problem of multi line replacement.