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: 

Splitting string...

Former Member
0 Kudos
151

Hello,

I have a string as follows:

C:\Documents and Settings\USER\Desktop\01.XML

I want to split this string as follows:

a) C:\Documents and Settings\USER\Desktop

b) 01.XML

Regards,

Jainam.

1 ACCEPTED SOLUTION

Former Member
0 Kudos
99

DATA : v_ch TYPE string VALUE 'C:\Documents and Settings\USER\Desktop\01.XML',

v_ch1 TYPE string,

v_ch2 TYPE string,

v_length TYPE i,

file TYPE i.

SPLIT v_ch AT '.XML' INTO v_ch1 v_ch2.

v_length = strlen( V_CH1 ).

DO .

v_length = v_length - 1.

IF v_ch1+v_length(1) = '\'.

v_length = v_length + 1.

WRITE v_ch1+v_length(file).

EXIT.

ENDIF.

file = file + 1.

ENDDO.

9 REPLIES 9

Former Member
0 Kudos
100

DATA : v_ch TYPE string VALUE 'C:\Documents and Settings\USER\Desktop\01.XML',

v_ch1 TYPE string,

v_ch2 TYPE string,

v_length TYPE i,

file TYPE i.

SPLIT v_ch AT '.XML' INTO v_ch1 v_ch2.

v_length = strlen( V_CH1 ).

DO .

v_length = v_length - 1.

IF v_ch1+v_length(1) = '\'.

v_length = v_length + 1.

WRITE v_ch1+v_length(file).

EXIT.

ENDIF.

file = file + 1.

ENDDO.

Former Member
0 Kudos
99

Hi,

Hope following code will be helpful.


data: v_string type string value 'C:\Documents and Settings\USER\Desktop\01.XML',
      v_string1(200) type c,
      v_string2(200) type c,
      v_len type i.

v_len = strlen( v_string ).

while v_len > 1.
 v_len = v_len - 1.
 v_string2+v_len(1) = v_string+v_len(1).
 if v_string+v_len(1) = '\'.
  clear v_string2+v_len(1).
  v_string1 = v_string+0(v_len).
  exit.
 endif.
endwhile.
condense v_string2.
write:/2 v_string1,
        /2 v_string2.

Cheers,

Vikram

Former Member
0 Kudos
99

Jainam,

i guess u are extracting file name and directory names from the string. are u sure that u will have this partern of string only? then only the above codes do work i think...

Former Member
0 Kudos
99

Hi,

Use Find with Results tab, Take the last offset position and split there.

See F1 help for FIND...RESULTS

Regards

Karthik D

Former Member
0 Kudos
99

use this fm SO_SPLIT_FILE_AND_PATH

Former Member
0 Kudos
99

Hi,

Use the FM 'CV120_SPLIT_PATH'...

or,

FM 'DSVAS_DOC_FILENAME_SPLIT'

This will solve your problem..

faisal_altaf2
Active Contributor
0 Kudos
99

Hi, Shah

Please Search Before Posting this Question has asked and answered so many times

You have got Lot of help here to So Please Close this Thread Now

Regards,

Faisal

Former Member
0 Kudos
99

data:
 val(250),
 result1 like val,
 result2 like val,
 my_index type i.


data:
  begin of itab occurs 0,
    val like val,
  end of itab.

val = 'C:\Documents and Settings\USER\Desktop\01.XML'.

split val at '\' into table itab.

describe table itab lines my_index.

read table itab index my_index.
if sy-subrc eq 0.
  result2 = itab-val.
  delete itab index my_index.
  loop at itab.
    concatenate result1 itab-val '\' into result1.
  endloop.
  write: RESULT1,/ RESULT2.
endif.

Former Member
0 Kudos
99

Hi,

Try using function module:

SO_SPLIT_FILE_AND_PATH

Hope it helps

Regards

Mansi