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

finding last char in the string

Former Member
0 Likes
5,605

Hi

i need to find out whether the last char of a string is '/' (forward slash). please let me know if there's a FM to do that. Other post me the logic for this ASAP.

thanks

Hi

i need to find out whether the last char of a string is '/' (forward slash). please let me know if there's a FM to do that. Other post me the logic for this ASAP.

thanks

9 REPLIES 9
Read only

Former Member
0 Likes
2,054

len = strlen( v_str ) - 1.

if v_str+len(1) = '/'.

*do something

endif.

Read only

Former Member
2,054


len = strlen(char).

len = len - 1.
if char+len(1) = '/'.
  *write ur code
endif.

chk this code

REPORT ychatest.

DATA : str(5) VALUE '123/',
       len TYPE i.

len = STRLEN( str ).

len = len - 1.
IF str+len(1) = '/'.
  WRITE : '/ found'.
ENDIF.

<b>Reward points if helpful and close thrad if solved</b>

Message was edited by: Chandrasekhar Jagarlamudi

Read only

Former Member
0 Likes
2,054

Hai Ramakrishna

data : v_find type string value 'abcdef/'.

data : v_length type i.

v_length = strlen( v_find ) - 1.

if v_find+v_length(1) = '/'.

write : /'yes'.

else.

write : /'No'.

endif.

Thanks & regards

Sreenivasulu P

Message was edited by: Sreenivasulu Ponnadi

Read only

Former Member
0 Likes
2,054

Hi Ramakrishna,

The following code snipet will helps your requirement.

data v_string type string.

data v_length type i.

v_length = strlen( v_string).

v_length = v_length - 1.

SEARCH v_string FOR '/' STARTING AT v_length.

if sy-subrc = 0.

write:/ 'Last character is / '.

esle.

write:/ 'Last character is not /'.

endif.

Thanks,

Vinay

Read only

rahulkavuri
Active Contributor
0 Likes
2,054

Equate the string to a char field of equal size.

Find the String length


str2(20) type c.

str2 = string.

n = strlen(string).

m = n - 1.

c = str2+m(1).

Read only

Former Member
0 Likes
2,054

hi

lastchar can b found using this


len = strlen( yourstring ) .
len = len - 1.

lastchar = yourstring+len(1).

Read only

Former Member
0 Likes
2,054

hi,

data : n TYPE I.

n = STRLEN( zfield ) - 1.

if zfield+n(1) = '/'.

  • code

endif

rgds,

latheesh

Read only

Former Member
0 Likes
2,054

hi Ram,

check the below code.

data: num type i.

data: const1(10) type c value 'thisis/'.

num = strlen( const1 ).

write: num.

num = num - 1.

if const1+num(1) = '/'.

message e000 with 'the last char is /'.

endif.

award pts if helpful.

regards,

keerthi.

Read only

Former Member
0 Likes
2,054

hi,

after declaring the string variable just fine the string length using <b>strlen</b>. then take the position of the last character of the string into an integer and using <b>offset</b> you can find whether the character in the desired position is '/' or not. the code is as follows :

DATA : STR TYPE string value 'abcde/'.

DATA : POS TYPE i.

POS = STRLEN( a ).

POS = POS - 1.

if STR+POS(1) = '/'.

*WRITE UR CODE HERE

endif.

pls award points if helpful.