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

REPLACE function 2

Status
Not open for further replies.

badrion

Programmer
Jul 16, 2001
34
US
I'm still alittle new with FoxPro but I need to search a field NAME for a "#" sign or an "@" sign and replace it with nothing. I tried to do a SEEK FOR then a REPLACE/WITH but it didn't work. I'm guessing I put it in the wrong order or syntax. Any help would be appreciated.
 
Hi badrion,

Do like following:
1. Create a function in your program
procedure convert
PARAME str
str=allt(str)
nLen=LEN(str)
newstr=''
FOR i=1 TO nLen
IF !INLIST(SUBSTR(str,i,1),'#','@')
newstr=newstr+SUBSTR(str,i,1)
ENDIF
ENDFOR
RETURN newstr


Now in your actual program write the following lines:
SELECT myTable
REPLACE ALL name with convert(name) ;
FOR ATC('@',name)<>0 OR ATC('#',name)<>0


Hope it works!

 
I think you'll find that:
SELECT mytable
REPLACE ALL name with CHRTRAN(name, &quot;@#&quot;, &quot;&quot;)

will be quicker.

Rick
 
Rick,

Thanks but it didn't work. It cleared out everything. Any other suggestions?
 
Rick,

I apologize, it did work. I had it in the wrong spot. That's the problem when working with someone else's code. Thank you SO much.!

Brandi
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top