The Nightman
The Nightman

Reputation: 5759

Get specific chars from a string in python

I want to make a new string from an internal part of an old string, and when I know the length of the string I know I can do this:

newString = oldString[6:145]

This exludes the first and last chars from the old string when writing the newString. But is there a way to do this if i dont know the length of the string, like:

newString = oldString[6:len(oldString)-6]

Thanks.

Upvotes: 1

Views: 60

Answers (1)

Maksim Solovjov
Maksim Solovjov

Reputation: 3157

Is this what you are looking for?

newString = oldString[6:-6]

Upvotes: 4

Related Questions