find ints in a string | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

find ints in a string

we have a string like this: *abcd*12*abcd*874647*abcd*837*abcd* and i wwnt to work just with ints.how i can seprate them?

2nd Jun 2018, 11:06 AM
mohamadjavad
mohamadjavad - avatar
2 Answers
+ 2
no idea how you are planning on using them since your question wasnt explained fully. here is one way https://code.sololearn.com/cnFfxqp4by0c/?ref=app
2nd Jun 2018, 11:28 AM
Markus Kaleton
Markus Kaleton - avatar
+ 1
It is simple. First, you need to split your string into entries (devided by "*"). Second, you need to check evey entry you got if it is an in integer. So, you need something like this: astring = "*abcd*12*abcd*874647*abcd*837*abcd*" entries = astring.split("*") for entry in entries: try: print(int(entry)) except: pass The result is: 12 874647 837
2nd Jun 2018, 11:21 AM
strawdog
strawdog - avatar