Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

how to remove all zeros that are 7 characters long python

I have made a string without spaces. so instead of spaces, I used 0000000. but there will be no alphabet letters. so for example, 000000020000000050000000190000000200000000 should equal "test". Sorry, I am very new to python and am not good. so if someone can help me out, that would be awesome.

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Unless I’m missing some context around your question, you are able to use the replace function to do this. It should be as simple as something like this:

my_string = '000000020000000050000000190000000200000000'

new_string = my_string.replace('0' * 7, '')

To get the literal word "test" you could even do something like replacing each ‘0000000’ with an actual space, and then splitting it by a space. Your code might look something like this:

new_string = my_string.replace('0' * 7, ' ')
characters = new_string.trim().split()

The characters array would then be ['20', '5', '19', '20'] which you can then convert to the alphabetical characters

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading