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

Function for first word in a sentence 1

Status
Not open for further replies.

SitesMasstec

Programmer
Sep 26, 2010
508
Brasil
Hello colleagues!

Is there a function to find the first word in a sentence?

For example:
Sentence: "John Travis Jr"

I want the result is the first word in the sentence: "John".

I can make a routine to find the same result, but I think VFP 9 has a function for that. I could not find it.


Thank you,
SitesMasstec
 
It depends how you define a sentence. In the example you gave, the "sentence" is in fact a person's name. If you have a field or variable that holds the name (and nothing else), then you can indeed use GETWORDNUM(). That would be easy.

But if the sentence is part of a longer piece of free text, it would be more difficult. You would have to parse the text, looking for the punctuation symbol that terminates the previous sentence. Is that what you want?

If all fails, you could always use Word Automation, given that Word is able to extract individual sentences from free text.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
I had to use this to find the first name in a table field:

Code:
USE mytable SHARED
GO (the relevant record number)
?GETWORDNUM(suppname, 1)  &&  Where [b]suppname[/b] is the field name and [b]1[/b] is the first word in that field

Hope that helps

Thank you

Steve Williams
VFP9, SP2, Windows 10
 
Hello collegues!

In my case, I would like to find the first name from a field.

I have a table with a field which contains the entire name of a person. So, I took the Criss advice to use GETWORDNUM(entire name, 1). My application is about sending e-mail which says in the Subject line, for example: Congratulations, John.


Thank you,
SitesMasstec
 
Hello,

pls. think of handling "Dr. John Travis jr."
Maybe you have the title in a separate field like we do.

Regards
tom

 
Useful remark, Tom.

In your example, I would test if the first occurence in the field is "Mr.", "Dr.", etc, or if the last character is a point (.). In this case we must apply ?GETWORDNUM(suppname, 2) to that record!



Thank you,
SitesMasstec
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top