2006 Dec 02 9:42 AM
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.
2006 Dec 02 9:43 AM
hi,
if str1+0(1) ='0'.
starts with zero.
else
not starts with zero.
endif.rgds
anver
2006 Dec 02 10:13 AM
SVJ,
u can try this code ...
if string+0(1) CA '0'.
write 😕 'Zero'.
else.
write 😕 'Non zero'.
endif.
2006 Dec 02 10:38 AM
if str(1) = '0'.
<leading 0>.
else.
<no 0>
endif.
regards
shiba dutta.
Message was edited by:
SHIBA DUTTA
2006 Dec 02 2:36 PM
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
| User | Count |
|---|---|
| 4 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |