Split keyword in ABAP when the separator is at the beginning and end of the string

We use the SPLIT keyword to SPLIT a string by a delimiter. If the delimiter is in the middle of the string (that is, if the first and last characters are not delimiters), we can easily see the result. But what if the delimiter is exactly the first or last of the string?
In the debug window, you can see all the row items in the inner table LT_SPLIT_TABLE after line 6 is executed, as shown in the following code.

DATA: lv_str         TYPE string,
      lt_split_table TYPE TABLE OF string.

lv_str = '/This/is/a/test./'.

SPLIT lv_str AT '/' INTO TABLE lt_split_table.


From the above test results, when the separator is at the beginning of the string, the left side of the separator will split an empty string; When a delimiter is at the end of a string, the empty string is not split to the right of the delimiter.

          DATA: lv_str   TYPE string,
                lt_split_table TYPE TABLE OF string,
                ls_split_table TYPE string.

          SPLIT lv_json AT '[' INTO str1 str2.
          SPLIT str2 AT ']' INTO TABLE lt_split_table.

          LOOP AT lt_split_table INTO ls_split_table.
            IF sy-tabix <> sy-tfill.       "The last line is not involved in splicing
              CONCATENATE str3 ls_split_table  INTO str3 .
            ENDIF.
          ENDLOOP.

          CONCATENATE '[' str3 ']' INTO o_return5 .

This splits str2 according to ‘] ‘, then removes the last one and splits it together.
This is one way to SPLIT a SPLIT from the right.

Read More: