Application Development 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: 

counting string length

Former Member
0 Kudos

i want the count of the number of integers used in the string '1,2,10,22,3,5' leaving commas.

plz help.

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi,

If the string has only integers and commas you can use:

FIND ALL OCCURRENCES OF ',' IN string MATCH COUNT mcnt.

The number of integers is mcnt + 1.

Regards.

Sandra Marques

6 REPLIES 6

Former Member
0 Kudos

Hi



data:p_string.  "Your string

data :w_num(10) value '0123456789',
        count type i.

w_len = strlen(p_string)


do w_len times.



if p_string+count(count + 1) CA sy-abcde.      "if character add character to output

chara = charct + 1.

elseif p_string+count(count + 1) CA w_num.          "if chara cter is number adding to number

nunber = number + 1.
endif.

count = count + 1.
enddo.


write : charat.

write : number.


Regards,

Prabhudas

Edited by: Prabhu Das on Apr 17, 2009 4:58 PM

Edited by: Prabhu Das on Apr 17, 2009 4:59 PM

Former Member
0 Kudos

Hi,

If the string has only integers and commas you can use:

FIND ALL OCCURRENCES OF ',' IN string MATCH COUNT mcnt.

The number of integers is mcnt + 1.

Regards.

Sandra Marques

Former Member
0 Kudos

Hi,



p_string "input string.

data : w_num(10) type '0123456789'.

data : begin of itab occurs 0,
            num type char10.
         end of itab.

split p_string at ',' into itab.

loop at itab.
if itab-num CA w_num.
count = count + 1.
endif.
endloop.

Former Member
0 Kudos

if its only commas and integers then you can do this way.

replace all occurence of ',' in p_string with space.
condense p_string.
len = strlen( p_string ).

Regards,

Lalit Mohan Gupta.

Former Member
0 Kudos

hi sonu,

chk this code snippet.

REPORT  znitesh1.
DATA: a TYPE string VALUE '1,2,3,,4,5,6'.
DATA: b TYPE i VALUE 0.
REPLACE ALL OCCURRENCES OF ',' IN a WITH ' '.
b = STRLEN( a ).
WRITE b.

thanks

Former Member
0 Kudos

if it is more than , and integers then you can do this way.

data: wa_num(10) value '0123456789',
count type i,
len type i.
len = strlen( p_string ).
do len times.
if p_string+0(1) ca wa_num.
count = count + 1.
endif.
shift p_string circular.
enddo.

Regards,

Lalit Mohan Gupta.