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 do i use substring in the following condition

I have a string with 80 characters length I am trying to substring this characters at certain index I did the following

Extract_32charcters_From_Begining = Text[0:32]
Extract_16charcters_after32index = Text[32:16]

in the above example I expected to get the first 32 characters at the beginning of the text then extract 16 characters after index 32 in the text. Extract_16charcters_after32index always returns 0 length. any idea what i am doing wrong ?

usually in PHP I do

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

substr($text, 32, 16);

isn’t the results should be same in python?

>Solution :

For that, you need a negative step value which is -1

Extract_16charcters_after32index = Text[32:16:-1]
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