Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Cut\Replace String ?

Former Member
0 Kudos

Given a String : 'c:\corp\dir\filename.pdf' .

I need to remove or replace with ' ' anything that comes after the last '\'.

The Replace has 'All occurences of ' or 'first occurence of' but not anything like last occurence .

1 ACCEPTED SOLUTION

former_member181962
Active Contributor
0 Kudos

Hi,

YOu can use the fm:

SO_SPLIT_FILE_AND_PATH

sample usage:

CALL FUNCTION 'SO_SPLIT_FILE_AND_PATH'

EXPORTING

full_name = fname

IMPORTING

stripped_name = short_fname

file_path = fpath

EXCEPTIONS

x_error = 1

OTHERS = 2.

Regards,

ravi

6 REPLIES 6

former_member181962
Active Contributor
0 Kudos

Hi,

YOu can use the fm:

SO_SPLIT_FILE_AND_PATH

sample usage:

CALL FUNCTION 'SO_SPLIT_FILE_AND_PATH'

EXPORTING

full_name = fname

IMPORTING

stripped_name = short_fname

file_path = fpath

EXCEPTIONS

x_error = 1

OTHERS = 2.

Regards,

ravi

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos

Please see this sample program.




REPORT ZRICH_0005 .

data: FULLNAME TYPE RLGRAP-FILENAME value 'C:tempfoldertext.txt' .

DATA: filename TYPE RLGRAP-FILENAME.
DATA: FILE_PATH TYPE RLGRAP-FILENAME.


CALL FUNCTION 'SO_SPLIT_FILE_AND_PATH'
  EXPORTING
    FULL_NAME           = FULLNAME
 IMPORTING
   STRIPPED_NAME       = filename
   FILE_PATH           = FILE_PATH
* EXCEPTIONS
*   X_ERROR             = 1
*   OTHERS              = 2
          .
IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.

write:/ fullname.
write:/ file_path.

Regards,

Rich Heilman

Former Member
0 Kudos

Translate String using '/ '.

Former Member
0 Kudos

Hi,

lv_data
lv_len

lv_len = strlen(lv_data).

n = lv_len
do n times.

  if lv_data+lv_len(1) = ''.
     lv_data = lv_data+0(lv_len).  
  else.
    lv_len = lv_len - 1.
  endif.
  
endo.

Reward points & mark Helpful Answers

former_member181962
Active Contributor
0 Kudos

Another way

split filename at '/' into table itab.

describe table itab lines v_lines.

loop at itab

if sy-tabix <> v_lines.

concatenate lv_filename itab-data into lv_filename separated by '/'.

endloop.

endloop.

lv_filename = lv_filename+1.

former_member188685
Active Contributor
0 Kudos

hi,

data: fname  LIKE rlgrap-filename,
      short_fname    LIKE rlgrap-filename,
      fpath          LIKE rlgrap-filename.
fname = 'c:corpdirfilename.pdf'.
  CALL FUNCTION 'SO_SPLIT_FILE_AND_PATH'
    EXPORTING
      full_name     = fname
    IMPORTING
      stripped_name = short_fname
      file_path     = fpath
    EXCEPTIONS
      x_error       = 1
      OTHERS        = 2.

regards

vijay