Quantcast
Channel: SCN: Message List
Viewing all articles
Browse latest Browse all 8851

Re: replace all occurrences of blanks only if it is preceded by space in string

$
0
0

Regular expression can be used here.

Run this snippet.

  1. DATA: str     TYPE char100 VALUE '10001:M :1001:          :NN',
  2.       results TYPE match_result_tab,
  3.       result  TYPE match_result,
  4.       off     TYPE i,
  5.       len     TYPE i.
  6. FIND ALL OCCURRENCES OF REGEX '([:,]) +' IN str RESULTS results.
  7. LOOP AT results INTO result.
  8.   off = result-offset.
  9.   len = result-length.
  10.   TRANSLATE str+off(len) USING ' _'.
  11. ENDLOOP.
  12. WRITE str.

Here I have chosen 2 delimiters and placed inside [] . Spaces followed by them will be replaced by underscore. You can modify the list of delimiters.

After finding all the valid patterns or substrings, translate statement is used for replacing spaces.

For more information about regular expressions, see keyword documentation and run program DEMO_REGEX_TOY.

 

/.


Viewing all articles
Browse latest Browse all 8851

Trending Articles