Skip to Content
avatar image
-2
Former Member

insert a space in a string in automatic basis after every 2 characters

Hi experts,

I have a string which is returning a value with different length for each system

and I need to return that value in a report with a better layout for that I need to insert a space in between every 2 characters, how can I do that?

example: original string value = D2F2G1V0E0M5B3

how I need to return it = D2 F2 G1 V0 E0 M5 B3

the problem is: the length of the original string is different for each system

thanks in advance and best regards,

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

3 Answers

  • Best Answer
    Jan 18 at 04:20 PM

    You can build your own logic. Eg.,

    Add comment
    10|10000 characters needed characters exceeded

  • Jan 18 at 05:07 PM
    Add comment
    10|10000 characters needed characters exceeded

  • Jan 22 at 04:48 PM

    Many possibilities:

    DATA lv_data TYPE string VALUE 'D2F2G1V0E0M5B3'.
    lv_data = replace( val = lv_data regex = '(..)' with = `$1 ` occ = 0 ).
    ASSERT lv_data = `D2 F2 G1 V0 E0 M5 B3 `.
    
    Add comment
    10|10000 characters needed characters exceeded