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

Character count of a string

Former Member
0 Likes
27,300

Hi,

I need to know wheter a variable has how many letters or composition of both letters and numbers.

Assume: var = '0200000010'.

Here the count is 10, I need to know this strings lenght, how can I do this?

Thanks.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
10,357

data len type i

data str type string value '1210000000'.

len = strlen( str ).

write 😕 len.

if you want only numbers from STR you can copy the value in a type 'n' variable so it will have only the numeric characters

the you can compare the length and if they are not same, you can know that there is a combination of letters and numbers, the length of the type 'n' variable will give you the count of numeric characters, and the difference in lengths will give you the count of characters.

Edited by: Priyank Jain on Aug 14, 2008 4:32 AM

4 REPLIES 4
Read only

Former Member
0 Likes
10,358

data len type i

data str type string value '1210000000'.

len = strlen( str ).

write 😕 len.

if you want only numbers from STR you can copy the value in a type 'n' variable so it will have only the numeric characters

the you can compare the length and if they are not same, you can know that there is a combination of letters and numbers, the length of the type 'n' variable will give you the count of numeric characters, and the difference in lengths will give you the count of characters.

Edited by: Priyank Jain on Aug 14, 2008 4:32 AM

Read only

former_member188829
Active Contributor
10,357

Hi

DATA: var TYPE string.
var = '0200000010'.
DATA:length type i.

length = STRLEN( VAR ).

WRITE:/ 'length is', length.

Read only

former_member585060
Active Contributor
0 Likes
10,357

Use FM

DATA : ABC type STRING

DATA : X type i.

ABC = '90ABDC0'.

CALL FUNCTION 'STRING_LENGTH'

IMPORTING

STRING = ABC

EXPORTING

LENGTH = X

.

WRTIE : X.

Read only

Former Member
0 Likes
10,357

Hi Deniz,

data: len type i.

If var co '0123456789'. "Contains only numbers

len = strlen( var ).

else.

condense var. "Remove leading and trailing space characters

len = strlen( var ).

endif.

Hope this helps

David Cooper