Bottom Page

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?
You like this post
Quote
#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.
You like this post
I am trying to help you, really, even if it doesn't always seem that way
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Extracting year from a string using strptime and datetime builtin Drone4four 3 155 Aug-11-2020, 12:02 PM
Last Post: ndc85430
  Add new line after finding last string in a region Nigel11 1 102 Aug-08-2020, 10:00 PM
Last Post: Larz60+
  String Comparing Harshil 15 341 Aug-05-2020, 05:50 PM
Last Post: Harshil
  string problem Mathisdlg 6 399 Aug-05-2020, 09:31 AM
Last Post: Mathisdlg
  Converting string to hex triplet menator01 4 162 Aug-03-2020, 01:00 PM
Last Post: deanhystad
  extract a dictionary from a string berc 4 294 Jul-30-2020, 06:58 AM
Last Post: berc
  string match Kristenl2784 1 134 Jul-28-2020, 03:14 PM
Last Post: Kristenl2784
  ValueError: could not convert string to float: RandomCoder 3 318 Jul-27-2020, 07:38 AM
Last Post: ndc85430
  Function parameters and values as string infobound 1 147 Jul-24-2020, 04:28 AM
Last Post: scidam
  Reverse a String ragav_in 3 154 Jul-24-2020, 02:24 AM
Last Post: ragav_in

Forum Jump:


Users browsing this thread: 1 Guest(s)