04-17-2009 12:22 PM
i want the count of the number of integers used in the string '1,2,10,22,3,5' leaving commas.
plz help.
04-17-2009 12:32 PM
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
04-17-2009 12:27 PM
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
04-17-2009 12:32 PM
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
04-17-2009 12:33 PM
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.
04-17-2009 12:45 PM
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.
04-17-2009 12:49 PM
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
04-17-2009 12:53 PM
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.