2021 Mar 08 7:53 AM
Dear all,
I'm looking for a way to replace all the spaces in a string, when they consequently occur more than one time, with a single 'Tab' character;
here a sample of the string
RAW MATERIAL TOOLS 82,000 59.083,200 52.062,420 148.121,834 0,000 0,000
and the desired result:
RAW MATERIAL TOOLS'Tab'82,000'Tab'59.083,200'Tab'52.062,420'Tab'148.121,834'Tab'0,000'Tab'0,000
is it possible to get the desired result with Regex?
any help is highly appreciated
thank you and best regards,
Flavio
2021 Mar 08 8:06 AM
Hello flavio.ciotola4
REPLACE ALL OCCURRENCES OF REGEX '[ ]{2,}' IN lv_string WITH cl_abap_char_utilities=>horizontal_tab.
Kind regards,Dear all,
I'm looking for a way to replace all the spaces in a string, when they consequently occur more than one time, with a single 'Tab' character;
here a sample of the string
RAW MATERIAL TOOLS 82,000 59.083,200 52.062,420 148.121,834 0,000 0,000
and the desired result:
RAW MATERIAL TOOLS'Tab'82,000'Tab'59.083,200'Tab'52.062,420'Tab'148.121,834'Tab'0,000'Tab'0,000
is it possible to get the desired result with Regex?
any help is highly appreciated
thank you and best regards,
Flavio
2021 Mar 08 8:04 AM
Hi, try this:
lv_string = replace( val = lv_string regex = '\s{2,}' with = cl_abap_char_utilities=>horizontal_tab occ = 0 ).
2021 Mar 08 8:06 AM
Hello flavio.ciotola4
REPLACE ALL OCCURRENCES OF REGEX '[ ]{2,}' IN lv_string WITH cl_abap_char_utilities=>horizontal_tab.
Kind regards,2021 Mar 08 8:47 AM
2021 Mar 08 9:41 AM
OCCURANCES -> OCCURRENCES 😉
Auto-test code:
data(lv_string) = |RAW MATERIAL TOOLS 82,000 59.083,200 52.062,420 148.121,834 0,000 0,000 |.
REPLACE ALL OCCURRENCES OF REGEX '[ ]{2,}' IN lv_string WITH cl_abap_char_utilities=>horizontal_tab.
assert lv_string = |RAW MATERIAL TOOLS\t82,000\t59.083,200\t52.062,420\t148.121,834\t0,000\t0,000\t|.
2021 Mar 08 10:00 AM
| User | Count |
|---|---|
| 3 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |