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

simple "replace" 2

Status
Not open for further replies.

foxup

Programmer
Dec 14, 2010
328
CA
Hi All,

I have a .DBF with over 150,000 records. Here's an example of what the data in the field (emails) looks like. They are all like this:

happy@mydomain.com
myname@abc123.ca
countvoncount@sesame.com
etc..

Basically I want to replace everything in front of the "@" sign with 'btn' and change it so that it looks like this:

btn@mydomain.com
btn@abc123.ca
btn@sesame.com

It's weird, I can't seem to find a simple REPLACE command.

Any help please.


Thanks,
FOXUP!
 
Actually, REPLACE isn't the command you want. REPLACE works on fields within tables. You need other functions for working with sub-strings.

Here's one way to achieve your goal:

Code:
x = "countvoncount@sesame.com"
? "btn" + STREXTRACT(x, "@", "", 1, 6)

For other possibilities, look at AT(), STRTRAN(), OCCURS(), GETWORDNUM(), etc.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 

replace all fieldname with 'btn'+SUBSTR(fieldname,AT('@',fieldname,1))


 
Me said:
Actually, REPLACE isn't the command you want. REPLACE works on fields within tables. You need other functions for working with sub-strings.

My mistake. I see now that you do want to replace the fields within a table. However, my code still holds good. You just need to amend it slightly, as follows:

Code:
REPLACE ALL MyField WITH "btn" + STREXTRACT(x, "@", "", 1, 6)

Sorry about that.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
You guys are awesome. I knew there was something I was doing wrong !! LOL Thanks a bunch. :) Stars for both of you. FOXUP!!
 
Gald to be of help, Foxup. But it was not something you were doing wrong. The FoxPro language has got a huge number of functions and commands, and even experienced developers have trouble remembering which one to use in a given case.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top