Warm tip: This article is reproduced from stackoverflow.com, please click
abap sap

Remove a special character that exists between 2 characters

发布于 2020-04-23 14:46:30

I have the following string:
6103951001#136,00#S0#0#99999999#8000010000#10.12.2019# 31.10.2019#"MATZOURAKIS IOANNISMROA118#OSPh"#99470##APE A 54226#K
What I want is to delete the special character HORIZONTAL_TAB(#) which is between " here is the part of the string: "MATZOURAKIS IOANNISMROA118#OSPh"
How can I do?
Thanks

PS. I am using the following to upload the data from a TAB delimited text file data: data_table type standard table of char255,

        wa_data_table like line of data_table.

  lv_file = p_file.
  cl_gui_frontend_services=>gui_upload(
    exporting
      filename                = lv_file
      filetype                = 'ASC'
    changing
      data_tab                = data_table

Now I am doing the following in order to catch the problem

  loop at data_table into wa_data_table.
    find all occurrences of '"' in wa_data_table match count lv_count.
    if sy-subrc = 0 and lv_count = 2.
*      REPLACE ALL OCCURRENCES OF REGEX
*      '(#(?=[^"]*"[^"]*(?:"[^"]*"[^"]*)*$))' IN wa_data_table WITH ' '.
      split wa_data_table at '"'
                            into split_data1 split_data2 split_data3.
      replace all occurrences of cl_abap_char_utilities=>horizontal_tab
             in split_data2 with ' '.
      concatenate split_data1 split_data2 split_data3
                                                  into wa_data_table.
    endif.
endloop.

I think that we must handle the cl_abap_char_utilities=>horizontal_tab not with the character # but in another way.

Questioner
ekekakos
Viewed
55
mrdeadsven 2020-02-18 19:46

You can use following in ABAP to find this character and replace it:

data : lv_test type string VALUE '6103951001#136,00#S0#0#99999999#8000010000#10.12.2019# 31.10.2019#"MATZOURAKIS IOANNISMROA118#OSPh"#99470##APE A 54226#K'.

REPLACE ALL OCCURRENCES OF REGEX '(#(?=[^"]*"[^"]*(?:"[^"]*"[^"]*)*$))' IN lv_test WITH ''.
write lv_test.

This is the correct solution for this problem.

  replace all occurrences of regex
                    '(\t(?=[^"]*"[^"]*(?:"[^"]*"[^"]*)*$))'
                    in table data_table with ' '.
  replace all occurrences of regex '["]' in table data_table with ''.