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!

Searching a field for a specific Character

Status
Not open for further replies.

rene316

Programmer
Jan 14, 2002
81
US
Hello,
I have a file with a first name field. The client would like us to make the first name field possesive, ie... John would be John's and James would be James'. Is there a quick line command or something that can do this. I figured if we search the first name field backwards until we encounter a character and check to see if it is an 's' or not, we could then make the name's possesive without messing the first name up, ie...James's. Any help would be much appreciated.

Thanks in advance,
Rene
 
You can use something like:
Code:
SCAN 
   IF UPPER(RIGHT(ALLTRIM(firstname), 1)) = "S"
      REPLACE firstname WITH ALLTRIM(firstname) + "'"
   ELSE
      REPLACE firstname WITH ALLTRIM(firstname) + "'s"
   ENDIF
ENDSCAN 

-or-

REPLACE ALL firstname WITH ;
   IIF(UPPER(RIGHT(ALLTRIM(firstname), 1)) = "S", ALLTRIM(firstname) + "'", ALLTRIM(firstname) + "'s")
Use 'ALL' after you have tested it on a few records to be sure of your results though.


-Dave S.-
[cheers]
Even more Fox stuff at:
 
You may want to add logic so that it only runs once per record...

e.g.

str1="abc's"
str2="abcs"

? CHR(39) $ str1
? CHR(39) $ str2

thus

replace all fieldname with [logic] and CHR(39) $ fieldname=.f.

Brian
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top