Application Development and Automation 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: 
Read only

string

Former Member
0 Likes
1,267

Hi Experts,

i have a string like this.

str = '00000003379#212RegVNegNoticeHLA.aspx.xml' So i want to read n.of characters from # to begin of the string. ie 00000003379#.The value for str will come dinamically.How can we do this?

Regards

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,239

lstr --> is your string

split lstr at '#' into lval lfile.

llen = strlen( lval ) + 1. (1 is to include the count for #).

Regards

Anurag

15 REPLIES 15
Read only

Former Member
0 Likes
1,239

Hi Ravi,

Try the "Split" statement :

split str at '#' into w_rec01 w_rec02.

Best Regards,

Erwan

Read only

0 Likes
1,239

1. Split the string at symbol # and store it in a variable

2. find the length of the string variable

regards

vivek

  • award points if this helps

Read only

0 Likes
1,239

Hi Experts

I have one long string and from which i should take only last 4 chars

how to do it

please tell me

rajesh

Read only

Former Member
0 Likes
1,239

Hello Ravi,

Use this code.

DATA: STR1 TYPE STRING,

STR2 TYPE STRING.

SPLIT STR AT '#' INTO STR1 STR2.

CONCATENATE STR1 '#' INTO STR1.

write: STR1.

If useful reward.

Vasanth

Read only

0 Likes
1,239

Hi,

Thanks for replies.

Problem is i am gettin value for str in debugging like this.

str = 00000003758#Account_Agreements-Combination.aspx.xml #

So at the end some where i am getting one more #.

Read only

0 Likes
1,239

str = 00000003758#Account_Agreements-Combination.aspx.xml #

v_len = strlen( str ).

v_len = v_len - 1.

str = str+0(v_len).

now use split at #

split str at '#' into v_num v_new.

Regards,

Ravi

Read only

0 Likes
1,239

ok , if you are uploading it from an excel file you will get that # at last , so add 3 more line to remove that

len = strlen( str ).
len = len - 1.
str = str+0(len).

so this will remove the last # from str

Read only

0 Likes
1,239

what if the second '#' is somewhere in between & not always at the end?

you can use the following to cover that scenario..

report  zp_string.
data w_str type 
     string value '00000003758#Account_Agre#ements-#Combination.aspx.xml #'.
data w_len type i.
data: w_str2 type string.

search w_str for '#' and mark.
w_len = sy-fdpos.
w_str2 = w_str+0(w_len).
write:/ w_str.
write:/ w_str2.

~Suresh

Read only

0 Likes
1,239

Hi Ravi,

You may n no of #'s in your line. To get length of string upto last '#' then try with this code.

DATA: L_LOC TYPE I,

L_LNG TYPE I,

L_CMD TYPE STRING,

L_FIL TYPE STRING,

STR TYPE STRING.

L_LENGTH = STRLEN( STR ).

L_LOC = 1.

WHILE SY-SUBRC = 0.

SEARCH STR FOR '#' STARTING AT L_LOC.

IF SY-FDPOS > 0.

ADD SY-FDPOS TO L_LOC.

L_CMD = STR(L_LOC).

L_LNG = L_LENGTH - L_LOC.

L_FIL = STR+L_LOC(L_LNG).

ELSE.

ADD 1 TO L_LOC.

ENDIF.

ENDWHILE.

WRITE:/ 'Length of string upto last # is ', L_LOC.

Thanks,

Vinay

Read only

0 Likes
1,239

Hi All,

thanks.

Read only

anversha_s
Active Contributor
0 Likes
1,239

hi,

try this.

SEARCH string for '#'.

l_from = sy-fdpos - 1.

search string for '#' starting at l_from.

l_to = sy-fdpos - 1.

l_len = l_to - l_from.

v_cutout = string+l_from(l_len).

Regards,

anver

Read only

Former Member
0 Likes
1,240

lstr --> is your string

split lstr at '#' into lval lfile.

llen = strlen( lval ) + 1. (1 is to include the count for #).

Regards

Anurag

Read only

Former Member
0 Likes
1,239
Hi Ravi,

 chk this

REPORT YCHATEST.

DATA : STR TYPE STRING,
       STR1 TYPE STRING,
       STR2 TYPE STRING,
       LEN TYPE I.

STR = '00000003379#212RegVNegNoticeHLA.aspx.xml'.

SPLIT STR AT '#' INTO STR1 STR2.

LEN = STRLEN( STR1 ).
LEN = LEN + 1.      " to include #

WRITE : LEN.

Read only

Former Member
0 Likes
1,239

Hi Ravi,

Try this:

split str at '#' into str1 str2.

if sy-subrc = 0.

l_count = strlen( str1 ).

endif.

Dharitree

Read only

Former Member
0 Likes
1,239

Hi,

use below logic

data lv_len type i.

str = '00000003379#212RegVNegNoticeHLA.aspx.xml'

search str for '#'.

lv_len = sy-fdpos - 1.

lv_len will have length of string.

<b>or

split str at '#' str1 str2.

lv_len = strlen(str1).</b>

Regards

amole