05-11-2010 7:38 AM
Hello Experts,
I have a requirement in which i have to find out the index of the last space before the 50th position in a string.
is there any way other than spliting the string.
e.g. if string is - 'aaaa aaaa aaa........ aaa aaa'(length is more than 50)
i want the last space before 50th char.because i want to split the string before last word withing 50 th character
please help.
Thanks,
Shweta
05-11-2010 7:46 AM
Hi,
data: w_50th(50).
w_text+0(50) = w_50th
data: i_var type i.
find space IN w_iang MATCH LENGTH i_var.
i_var contans the index value..
05-11-2010 8:14 AM
Hi Shweta,
You can build up the logic from this below program.
data: line(75) value 'abcdefghijk lmnopqrstuvwxyz zyxwvutsrqponml kjihgfedc ba',
n_line(50),
off type i,
val1(50),
val2(50).
CALL FUNCTION 'STRING_REVERSE'
EXPORTING
STRING = line(50)
LANG = ' '
IMPORTING
RSTRING = n_line
EXCEPTIONS
TOO_SMALL = 1
OTHERS = 2.
IF SY-SUBRC NE 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
SPLIT n_line at space into val1 val2.
off = strlen( val1 ).
off = 50 - off.
write: 'The index of the last space before the 50th position is at ', off.
Hope this may help you.
Regards,
Smart Varghese
05-11-2010 9:14 AM
Hello Smart Varghese,
thanks for your reply.
It is working for me.
Regards,
Shweta