Python Forum
How to find previous string of a string
Thread Rating:
  • 1 Vote(s) - 1 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to find previous string of a string
#1
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?
Reply
#2
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.
I am trying to help you, really, even if it doesn't always seem that way
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  comtypes: how to provinde a list of string to a COM method zalanthas 0 130 Jun-26-2024, 01:27 PM
Last Post: zalanthas
  TypeError: string indices must be integers, not 'str' LEMA 2 258 Jun-12-2024, 09:32 PM
Last Post: LEMA
  Formatting DateTime string and and converting it from AM/PM to 24 hours tester_V 2 255 Jun-08-2024, 05:16 PM
Last Post: tester_V
  Use or raw string on regular expressions Zaya_pool 5 544 May-09-2024, 06:10 PM
Last Post: Zaya_pool
  How do I parse the string? anna17 4 571 Apr-10-2024, 10:26 AM
Last Post: DeaD_EyE
  remove gilberishs from a "string" kucingkembar 2 435 Mar-15-2024, 08:51 AM
Last Post: kucingkembar
  Matching string from a file tester_V 5 688 Mar-05-2024, 05:46 AM
Last Post: Danishhafeez
  Python3 string slicing Luchano55 4 820 Feb-17-2024, 09:40 AM
Last Post: Pedroski55
  Retrieve word from string knob 4 715 Jan-22-2024, 06:40 PM
Last Post: Pedroski55
  Writing a Linear Search algorithm - malformed string representation Drone4four 10 1,413 Jan-10-2024, 08:39 AM
Last Post: gulshan212

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020