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

how to check a string

Former Member
0 Likes
1,145

Hi,

How to check if a string (str1) starts with a ' 0 ' (zero) or not.

Thank you.

Hi,

How to check if a string (str1) starts with a ' 0 ' (zero) or not.

Thank you.

4 REPLIES 4
Read only

anversha_s
Active Contributor
0 Likes
1,037

hi,

if str1+0(1) ='0'.
starts with zero.
else
not starts with zero.
endif.

rgds

anver

Read only

Former Member
0 Likes
1,037

SVJ,

u can try this code ...

if string+0(1) CA '0'.

write 😕 'Zero'.

else.

write 😕 'Non zero'.

endif.

Read only

Former Member
0 Likes
1,037

if str(1) = '0'.

<leading 0>.

else.

<no 0>

endif.

regards

shiba dutta.

Message was edited by:

SHIBA DUTTA

Read only

Clemenss
Active Contributor
0 Likes
1,037

Hi,

the proposals are correct but incomplete and dangerous because empty strings will result in a dump. The offset +0(1) is invalid for length zero.

This could be a nice application for a functional method:


method starts_with_zero.
if strlen( str1 ) > 0.
  if str1(1) = '0'.
    result = 'X'.
  else.
    result = space.
  endif.
endif.

Define a local or dictionary class z_util with static method (CLASS-METHODS) starts_with_zero. Define str1 type string as importing parameter, value(result) type xfeld as returning parameter.

The in your program, use something like.


CHECK z_util=>starts_with_zero( anystring ) is initial.
* continue for string anystring if not starting with Zero

Note: I love functional static methods - they can make programs more easy to read and write.

Regards,

Clemens