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

Split string after x characters using split()

I’m having issues splitting a string. I need it to be split after the first character and then after the following four, but I’m not sure on how to do it.
As an example, for the input 123456789, I would need it to be split into [‘1′,’2345′,’6789’].
Any help would be appreciated.

>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

>>> s = "123456789"
>>> s[0], s[1:5], s[5:]
('1', '2345', '6789')

Like this? Will format always be the same? Or is it anyhow conditional?

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