Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Best Way To Extract Sub-Strings From a String 1

Status
Not open for further replies.

cascot

Programmer
Jan 30, 2002
127
CA
I want to extract a series of Needles (Sub-Strings) from a Haystack (String). I will always extract the Needles in ascending order of appearence within the Haystack. When I previously did such a task using VBA I was able to work with the same "Original" string, beginning the search for each new needle only from a chosen character of the string (to use a book analogy...the search for Needle1 would begin on page 1, but by the time I was searching for Needle10 I may only be starting the search on page 25).

So far I can only find AnsiPos which begins each search from character 1 of the string. Does this mean I effectively have to search for Needle1 then chop it (and all characters that precede it) off the beginning of the string before beginning my search for Needle2 (thus the search, as in the VBA example, will now only be searching from the characters immediately following the last found needle)? Or is there a better way?
 

What you want is the PosEx() function.

Add StrUtils to your uses clause.


 
Zathras,

Thank you, that's exactly it. PosEx isn't featured in the book I am reading (though I'm using a Delphi4 book) or the site I am using as a reference tool, so I'm very glad you pointed me in the right direction. It'll mean a lot less code, and a more efficient solution.

Thanks again.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top