Xojo Conferences
XDCMay2019MiamiUSA

Graceful Way to Search Backwards in Text? (Real Studio network user group Mailinglist archive)

Back to the thread list
Previous thread: 5.2.1
Next thread: AW: How can i get a date via OLE Automation?


File handling ideas ???   -   Jan Erik Moström <
  Graceful Way to Search Backwards in Text?   -   Patrick Salo
   Re: Graceful Way to Search Backwards in Text?   -   Andrew Bush
    Re: Graceful Way to Search Backwards in Text?   -   newtdude citlink.net
     Re: Graceful Way to Search Backwards in Text?   -   Kevin Ballard
     Re: Graceful Way to Search Backwards in Text?   -   Will Leshner
      Re: Graceful Way to Search Backwards in Text?   -   Brad Hutchings
     Re: Graceful Way to Search Backwards in Text?   -   Andrew Bush
      Re: Graceful Way to Search Backwards in Text?   -   Kevin Ballard
    Re: Graceful Way to Search Backwards in Text?   -   Joseph J. Strout
     Re: Graceful Way to Search Backwards in Text?   -   Patrick Salo
   Re: Graceful Way to Search Backwards in Text?   -   Joel Rosenblum
   Re: Graceful Way to Search Backwards in Text?   -   Norman Palardy
   Re: Graceful Way to Search Backwards in Text?   -   John Moore
   Re: Graceful Way to Search Backwards in Text?   -   Theodore H. Smith
   Re: Graceful Way to Search Backwards in Text?   -   Theodore H. Smith

Graceful Way to Search Backwards in Text?
Date: 13.08.03 09:32 (Wed, 13 Aug 2003 01:32:58 -0700)
From: Patrick Salo
Is there a way to search a string/text backwards in a graceful manner?
I've researched InStr and InStrB but they both only seem to do forward
searches (as does RegEx from what I can tell).

I realize that I could probably homebrew my own via the start parameter
in InStr and InStrB by doing something similar to this (psuedo code):
- Find length of string
- Perform a loop that:
- Sets the InStr start to string length - X characters
- Performs a Search
- If a match is found return
- Otherwise reduce string length again by X
- Loop again
This would work but would be a bit slow and cumbersome as I would
imagine that I would need to search for partial pieces of the search
text if I step backwards by multiple characters or continuously step
backwards by by 1 character to find full matches (no, please no! =)

TIA,

Patrick Salo
<email address removed>

---
A searchable archive of this list is available at:
<http://support.realsoftware.com/listarchives/search.php>

Unsubscribe or switch delivery mode:
<http://support.realsoftware.com/listmanager/>

Re: Graceful Way to Search Backwards in Text?
Date: 13.08.03 11:00 (Wed, 13 Aug 2003 22:00:34 +1200)
From: Andrew Bush
Hi Patrick,

what strings exactly are you searching for?

my 'first response' to your question is that you should simply search
forward for the reversed string.

ie, if you would search backward for the sub string "orp", this is the
same as searching forward for the substring "pro"

but it does depends on what you are after :)

Yours cheerfully,

Andrew Bush

On Wednesday, August 13, 2003, at 08:32 PM, Patrick Salo wrote:

> Is there a way to search a string/text backwards in a graceful manner? I'
> ve researched InStr and InStrB but they both only seem to do forward
> searches (as does RegEx from what I can tell).
>
> I realize that I could probably homebrew my own via the start parameter
> in InStr and InStrB by doing something similar to this (psuedo code):
> - Find length of string
> - Perform a loop that:
> - Sets the InStr start to string length - X characters
> - Performs a Search
> - If a match is found return
> - Otherwise reduce string length again by X
> - Loop again
> This would work but would be a bit slow and cumbersome as I would imagine
> that I would need to search for partial pieces of the search text if I
> step backwards by multiple characters or continuously step backwards by
> by 1 character to find full matches (no, please no! =)
>
> TIA,
>
> Patrick Salo
> <email address removed>
> ---
> A searchable archive of this list is available at:
> <http://support.realsoftware.com/listarchives/search.php>
> Unsubscribe or switch delivery mode:
> <http://support.realsoftware.com/listmanager/>
"I'm talking to all of you, here!" continued God, His voice rising to a
shout. "Do you hear Me? I don't want you to kill anybody. I'm against it,
across the board. How many times do I have to say it? Don't kill each
other any more, ever! I'm fucking serious!"
 
Upon completing His outburst, God fell silent, standing quietly at the
podium for several moments. Then, witnesses reported, God's shoulders
began to shake, and He wept.

(Quote from http://www.theonion.com/onion3734/god_clarifies_dont_kill.html)

---
A searchable archive of this list is available at:
<http://support.realsoftware.com/listarchives/search.php>

Unsubscribe or switch delivery mode:
<http://support.realsoftware.com/listmanager/>

Re: Graceful Way to Search Backwards in Text?
Date: 13.08.03 20:09 (Wed, 13 Aug 2003 19:09:57 +0000)
From: newtdude citlink.net
All,

Thank you for your suggestions. The Elf plugin may work in this instance and
I may try this. Concerning the other two posts about searching for the
reversed characters...I don't know if I quite understand but would like to
as this seems like an important concept. I don't quite understand how
searching for agemo instead of omega will deliver a result as agemo isn't in
my text.

Here is what I'm trying to do: I have some text, do an initial search to
find a specific word but would like to search backwards from that selection
point to find the prior instance of "Chapter #". My purpose in doing this is
so that I can determine which chapter section I may find for example the
word "omega" in.

Patrick Salo
<email address removed>

Andrew Bush writes:

> Hi Patrick,
>
> what strings exactly are you searching for?
>
> my 'first response' to your question is that you should simply search
> forward for the reversed string.
>
> ie, if you would search backward for the sub string "orp", this is the
> same as searching forward for the substring "pro"
>
> but it does depends on what you are after :)
>
> Yours cheerfully,
>
> Andrew Bush

---
A searchable archive of this list is available at:
<http://support.realsoftware.com/listarchives/search.php>

Unsubscribe or switch delivery mode:
<http://support.realsoftware.com/listmanager/>

Re: Graceful Way to Search Backwards in Text?
Date: 13.08.03 20:12 (Wed, 13 Aug 2003 14:12:35 -0500)
From: Kevin Ballard
I think the idea was to reverse the text you're searching for AND the
text you're searching in. That way you get the result from the end of
the string. If you want 'omega', you don't have 'agemo' in your string,
no, but you do have it in your reversed string.

Of course, depending on the size of your strings, reversing them may be
slow (it would be much faster if you could rely on having all
single-byte chars, i.e. ASCII or MacRoman or WindowsLatin1 or something)

On Wednesday, August 13, 2003, at 02:09 PM, <email address removed> wrote:

> All,
> Thank you for your suggestions. The Elf plugin may work in this
> instance and I may try this. Concerning the other two posts about
> searching for the reversed characters...I don't know if I quite
> understand but would like to as this seems like an important concept.
> I don't quite understand how searching for agemo instead of omega will
> deliver a result as agemo isn't in my text.
> Here is what I'm trying to do: I have some text, do an initial search
> to find a specific word but would like to search backwards from that
> selection point to find the prior instance of "Chapter #". My purpose
> in doing this is so that I can determine which chapter section I may
> find for example the word "omega" in.

Re: Graceful Way to Search Backwards in Text?
Date: 13.08.03 20:15 (Wed, 13 Aug 2003 12:15:03 -0700)
From: Will Leshner
So you could search for both 'Chapter' and 'omega'. When you find
'Chapter', remember it. When you find 'omega' go back to your last
'Chapter' and you are done.

<email address removed> wrote:

> All,
> Thank you for your suggestions. The Elf plugin may work in this instance
> and I may try this. Concerning the other two posts about searching for
> the reversed characters...I don't know if I quite understand but would
> like to as this seems like an important concept. I don't quite
> understand how searching for agemo instead of omega will deliver a
> result as agemo isn't in my text.
> Here is what I'm trying to do: I have some text, do an initial search to
> find a specific word but would like to search backwards from that
> selection point to find the prior instance of "Chapter #". My purpose in
> doing this is so that I can determine which chapter section I may find
> for example the word "omega" in.



---
A searchable archive of this list is available at:
<http://support.realsoftware.com/listarchives/search.php>

Unsubscribe or switch delivery mode:
<http://support.realsoftware.com/listmanager/>

Re: Graceful Way to Search Backwards in Text?
Date: 13.08.03 20:29 (Wed, 13 Aug 2003 12:29:09 -0700)
From: Brad Hutchings
It sounds like you are trying to implement forward and reverse search
as user functions. If so, change your strategy a little bit. When the
user initiates a search (from wherever, and assuming that the text
isn't so long that this bogs down), find all occurences using repeated
calls to InStr (which is plenty fast for most uses), cache them in an
array, and the binary search the array for the right next or previous
instance for any position in the text you wind up with. This technique
is fully discussed in the computer science classic... no, I'm kidding,
I just made that up from the top of my head but I bet it will feel
faster to the user than any incremental approach you can come up with.
No plugin required.

-Brad

Re: Graceful Way to Search Backwards in Text?
Date: 13.08.03 23:05 (Thu, 14 Aug 2003 10:05:39 +1200)
From: Andrew Bush
Hi Patrick,

ah, ok.

For this I would do as another poster suggested and search for both omega
_and_ chapter, each occurance of chapter would be cached along with the
offset it occured at, and when the omega is found you can just find the
closest matching chapter.

I would look at the regex class for doing the combined search.

Yours cheerfully,

Andrew bush

> All,
> Thank you for your suggestions. The Elf plugin may work in this instance
> and I may try this. Concerning the other two posts about searching for
> the reversed characters...I don't know if I quite understand but would
> like to as this seems like an important concept. I don't quite
> understand how searching for agemo instead of omega will deliver a result
> as agemo isn't in my text.
> Here is what I'm trying to do: I have some text, do an initial search to
> find a specific word but would like to search backwards from that
> selection point to find the prior instance of "Chapter #". My purpose in
> doing this is so that I can determine which chapter section I may find
> for example the word "omega" in.
> Patrick Salo
> <email address removed>
> Andrew Bush writes:
>> Hi Patrick, what strings exactly are you searching for? my 'first
>> response' to your question is that you should simply search forward for
>> the reversed string. ie, if you would search backward for the sub string
>> "orp", this is the same as searching forward for the substring "pro" but
>> it does depends on what you are after :) Yours cheerfully, Andrew Bush
>
> ---
> A searchable archive of this list is available at:
> <http://support.realsoftware.com/listarchives/search.php>
> Unsubscribe or switch delivery mode:
> <http://support.realsoftware.com/listmanager/>
Real Programmers consider "what you see is what you get" to be just as
bad a concept in Text Editors as it is in women. No, the Real Programmer
wants a "you asked for it, you got it" text editor -- complicated,
cryptic, powerful, unforgiving, dangerous.

---
A searchable archive of this list is available at:
<http://support.realsoftware.com/listarchives/search.php>

Unsubscribe or switch delivery mode:
<http://support.realsoftware.com/listmanager/>

Re: Graceful Way to Search Backwards in Text?
Date: 13.08.03 23:11 (Wed, 13 Aug 2003 17:11:24 -0500)
From: Kevin Ballard
Mmm... RegEx...

Assuming the text is formatted

blah...blah...blah...
chapter 45
blah...blah...
chatper 46
blah...omega...blah...
chapter 47
...

Then to find the chapter number, try the regex

chapter (\d+).*?omega

Then RegExMatch.SubExpressionString(1) will contain the chapter number
that has the first occurrence of the word 'omega' in it.

On Wednesday, August 13, 2003, at 05:05 PM, Andrew Bush wrote:

> For this I would do as another poster suggested and search for both
> omega _and_ chapter, each occurance of chapter would be cached along
> with the offset it occured at, and when the omega is found you can
> just find the closest matching chapter.
>
> I would look at the regex class for doing the combined search.

Re: Graceful Way to Search Backwards in Text?
Date: 13.08.03 20:26 (Wed, 13 Aug 2003 12:26:14 -0700)
From: Joseph J. Strout
This thread does illustrate the need for a reverse version of
InStr[B] (and maybe an easy way to reverse a string, too). Feel free
to file feature requests.

Best,
- Joe

Re: Graceful Way to Search Backwards in Text?
Date: 15.08.03 01:27 (Thu, 14 Aug 2003 17:27:45 -0700)
From: Patrick Salo
Thank you for your help everyone!

I decided not to do the string/text reversal as the text is fairly long
but instead have implemented the chapter/word search that a couple of
you recommended. This was actually pretty easy to implement and works
great! Thank you for the idea to use ElfData Theodore. I didn't go
that route this time around but I'll keep the idea in the back of my
head for maybe the next time. Joe thanks for the recommendation below.
I'll submit something later on tonight when I get a chance.

Once again, you guys/gals are the greatest! =)

Patrick

On Wednesday, Aug 13, 2003, at 12:26 US/Pacific, Joseph J. Strout wrote:

> This thread does illustrate the need for a reverse version of InStr[B]
> (and maybe an easy way to reverse a string, too). Feel free to file
> feature requests.
>
> Best,
> - Joe
>
> --
> ,------------------------------------------------------------------.
> | Joseph J. Strout REAL Software, Inc. |
> | <email address removed> http://www.realsoftware.com |
> `------------------------------------------------------------------'
>
> ---
> A searchable archive of this list is available at:
> <http://support.realsoftware.com/listarchives/search.php>
> Unsubscribe or switch delivery mode:
> <http://support.realsoftware.com/listmanager/>

---
A searchable archive of this list is available at:
<http://support.realsoftware.com/listarchives/search.php>

Unsubscribe or switch delivery mode:
<http://support.realsoftware.com/listmanager/>

Re: Graceful Way to Search Backwards in Text?
Date: 13.08.03 16:52 (Wed, 13 Aug 2003 11:52:11 -0400)
From: Joel Rosenblum
You need the ElfData plugin, at elfdata.com. It will solve your string
processing needs.

At 01:32 AM 8/13/2003 -0700, you wrote:
>Is there a way to search a string/text backwards in a graceful manner?
>I've researched InStr and InStrB but they both only seem to do forward
>searches (as does RegEx from what I can tell).
>
>I realize that I could probably homebrew my own via the start parameter in
>InStr and InStrB by doing something similar to this (psuedo code):
> - Find length of string
> - Perform a loop that:
> - Sets the InStr start to string length - X characters
> - Performs a Search
> - If a match is found return
> - Otherwise reduce string length again by X
> - Loop again
>This would work but would be a bit slow and cumbersome as I would imagine
>that I would need to search for partial pieces of the search text if I
>step backwards by multiple characters or continuously step backwards by by
>1 character to find full matches (no, please no! =)
>
>TIA,
>
>Patrick Salo
><email address removed>
>---
>A searchable archive of this list is available at:
><http://support.realsoftware.com/listarchives/search.php>
>Unsubscribe or switch delivery mode:
><http://support.realsoftware.com/listmanager/>

---
A searchable archive of this list is available at:
<http://support.realsoftware.com/listarchives/search.php>

Unsubscribe or switch delivery mode:
<http://support.realsoftware.com/listmanager/>

Re: Graceful Way to Search Backwards in Text?
Date: 13.08.03 17:12 (Wed, 13 Aug 2003 10:12:16 -0600)
From: Norman Palardy
Or, reverse the string and the pattern your searching for and work
forwards ?

On Wednesday, August 13, 2003, at 02:32 AM, Patrick Salo wrote:

> Is there a way to search a string/text backwards in a graceful manner?
> I've researched InStr and InStrB but they both only seem to do
> forward searches (as does RegEx from what I can tell).
>
> I realize that I could probably homebrew my own via the start
> parameter in InStr and InStrB by doing something similar to this
> (psuedo code):
> - Find length of string
> - Perform a loop that:
> - Sets the InStr start to string length - X characters
> - Performs a Search
> - If a match is found return
> - Otherwise reduce string length again by X
> - Loop again
> This would work but would be a bit slow and cumbersome as I would
> imagine that I would need to search for partial pieces of the search
> text if I step backwards by multiple characters or continuously step
> backwards by by 1 character to find full matches (no, please no! =)
>
> TIA,
>
> Patrick Salo
> <email address removed>
> ---
> A searchable archive of this list is available at:
> <http://support.realsoftware.com/listarchives/search.php>
> Unsubscribe or switch delivery mode:
> <http://support.realsoftware.com/listmanager/>

---
A searchable archive of this list is available at:
<http://support.realsoftware.com/listarchives/search.php>

Unsubscribe or switch delivery mode:
<http://support.realsoftware.com/listmanager/>

Re: Graceful Way to Search Backwards in Text?
Date: 17.08.03 03:56 (Sat, 16 Aug 2003 20:56:27 -0600)
From: John Moore
I haven't had to do this in RB, but I've done it in C++. It was pretty
trivial if I remember correctly. Should be just as easy in RB.
On Wednesday, August 13, 2003, at 02:32 AM, Patrick Salo wrote:

> Is there a way to search a string/text backwards in a graceful manner?
> I've researched InStr and InStrB but they both only seem to do
> forward searches (as does RegEx from what I can tell).
>
> I realize that I could probably homebrew my own via the start
> parameter in InStr and InStrB by doing something similar to this
> (psuedo code):
> - Find length of string
> - Perform a loop that:
> - Sets the InStr start to string length - X characters
> - Performs a Search
> - If a match is found return
> - Otherwise reduce string length again by X
> - Loop again
> This would work but would be a bit slow and cumbersome as I would
> imagine that I would need to search for partial pieces of the search
> text if I step backwards by multiple characters or continuously step
> backwards by by 1 character to find full matches (no, please no! =)
>
> TIA,
>
> Patrick Salo
> <email address removed>
> ---
> A searchable archive of this list is available at:
> <http://support.realsoftware.com/listarchives/search.php>
> Unsubscribe or switch delivery mode:
> <http://support.realsoftware.com/listmanager/>

---
A searchable archive of this list is available at:
<http://support.realsoftware.com/listarchives/search.php>

Unsubscribe or switch delivery mode:
<http://support.realsoftware.com/listmanager/>

Re: Graceful Way to Search Backwards in Text?
Date: 13.08.03 20:30 (Wed, 13 Aug 2003 20:30:36 +0100)
From: Theodore H. Smith
Hi Patrick,

the ElfData plugin allows this. You can do this kind of searching, and
far more with it. You can read about it, at www.elfdata.com/plugin/

> Thank you for your suggestions. The Elf plugin may work in this
> instance and
> I may try this. Concerning the other two posts about searching for the
> reversed characters...I don't know if I quite understand but would
> like to
> as this seems like an important concept. I don't quite understand how
> searching for agemo instead of omega will deliver a result as agemo
> isn't in
> my text.
>
> Here is what I'm trying to do: I have some text, do an initial search
> to
> find a specific word but would like to search backwards from that
> selection
> point to find the prior instance of "Chapter #". My purpose in doing
> this is
> so that I can determine which chapter section I may find for example
> the
> word "omega" in.
>
> Patrick Salo
> <email address removed>
> Andrew Bush writes:
>
>> Hi Patrick,
>>
>> what strings exactly are you searching for?
>>
>> my 'first response' to your question is that you should simply search
>> forward for the reversed string.
>>
>> ie, if you would search backward for the sub string "orp", this is the
>> same as searching forward for the substring "pro"
>>
>> but it does depends on what you are after :)
>>
>> Yours cheerfully,
>>
>> Andrew Bush

---
A searchable archive of this list is available at:
<http://support.realsoftware.com/listarchives/search.php>

Unsubscribe or switch delivery mode:
<http://support.realsoftware.com/listmanager/>

Re: Graceful Way to Search Backwards in Text?
Date: 14.08.03 10:03 (Thu, 14 Aug 2003 10:03:48 +0100)
From: Theodore H. Smith
That seems more complex, than just calling:

"MyData.InRevStr( MySearchPattern )" :o)

You can use the ElfData plugin for insensitive, or case sensitive
searching, also. It's at www.elfdata.com/plugin/

There is an older version, "Theo's String Stuff plugin", however that
is only case-sensitive (B-version). The advantage is that it doesn't
require you to work on an "ElfData object", but uses RB strings. While
that's not a problem for anyone making new code, existing code would
require some patching to the ElfData plugin.

> Mmm... RegEx...
>
> Assuming the text is formatted
>
> blah...blah...blah...
> chapter 45
> blah...blah...
> chatper 46
> blah...omega...blah...
> chapter 47
> ...
>
> Then to find the chapter number, try the regex
>
> chapter (\d+).*?omega
>
> Then RegExMatch.SubExpressionString(1) will contain the chapter number
> that has the first occurrence of the word 'omega' in it.
>