[Tutor] count numbers only in the string

kumar s ps_python at yahoo.com
Tue Mar 6 21:07:59 CET 2012


Hi :

I have some strings with both alpha-numeric strings. I want to add all the numbers in that string and leave characters and special characters. 
1A0G19

5G0C25^C52

0G2T3T91
44^C70

How can I count only the numbers in the above. 

1 A 0 G 19       =    1+0+19 = 20

5 G 0 C 25 ^C 52  =   5+0+25+52 = 82

0 G 2 T 3 T 91    =  0+2+3+91 =  96
44 ^C 70   =   44+70 =  114

 In first string 1A0G19  I am only adding 1, 0, and 19.    I am not splitting 19 to add 1+9 which will give totally wrong answer for me.


Is there a way I can do this. 

Thanks for your advise. 

kumar



More information about the Tutor mailing list