How to find previous string of a string - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: How to find previous string of a string (/thread-13067.html) |
How to find previous string of a string - Prince_Bhatia - Sep-26-2018 Hi, I am struggling at problem which is how to find previous string in a string. For example i have a string A= "my name is prince" Now i want to find "prince" when prince found return "my name is" How can i do that? RE: How to find previous string of a string - gruntfutuk - Sep-26-2018 Explore string slicing. See what the below gives you (the literal string can be replaced by a variable). "Mary had a little lamb"[:10] So, you can find where the string you are looking for starts, and then slice the string to return everything before that. |