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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

start and end point detection

Status
Not open for further replies.

Fairuzinho

Programmer
Jun 25, 2002
10
US
hello....can anybody give me a source code on how to detect the start and end point between two word like if we say 'eat me', the code must detect the start and end of the word 'eat' and as same as for word 'me'.....ok thank you..
 
Try using the function Pos, which returns the position of the first character of the string you are searching for.

For example:
Code:
Pos('eat', sentenceStr)
if Pos returns 0, then there is no instance of 'eat' in sentenceStr.


Peter Tickler
 
I did something similar for a search, couldn't use Pos as this would return true for part words and I wanted whole words. I read my text in to a TStringStream, as it could be quite long. Then, search through the string char be char - you need to look for non alphabetical characters (eg space, commas, % £ " [ etc), then read/return the words between them.

If you have real trouble, I can post some example code but it is easier than it sounds.

lou
 
The excellent HyperStr library has functions for parsing tokens (words) from a string.

You specify a string containing all the delimiters that can separate words - eg space, comma, fullstop, brackets and the like.

Using your example, you would code up something like this:
Code:
  str := 'He said "please do not eat me!"';
  delims := ' !,.()[]{};:-?''"';
  x := 1;         // Point x at the start of str
  repeat
    token := Parse ( str, delims, x );
  until ( x<1 ) or ( x > Length(str) ) or ( token='eat' );
x points to the token within str. When the code finds 'eat', x will have been incremented past it so you will need to save x.

HyperStr, which is freeware, can be found at



Andrew
 
Thank you about your reply on my problem....but still cannot understand....can you all give me come example for the coding....i mean the source code...ok thank you...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top