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

Need to replace certain characters in a string 4

Status
Not open for further replies.

TreizeRXH

MIS
Sep 17, 2015
6
0
0
US
I have a column (let's call it 'column1') that contains codes that follow this pattern (651xxx)

i'm trying to update the first three characters so that all the data will read 652xxx.

I've tried using strtran but I can't seem to get the syntax right. ANy help on this would be appreciated
 
What syntax have you been trying to use?

I'd first recommend that you create a Copy of your data table and do your testing on that until you get things the way you want.

Typically you might use something like:
Code:
REPLACE ALL Col1 WITH "652" + SUBSTR(ALLTRIM(Col1),4)  && Make all values "652" + chars 4 to last
OR
Code:
REPLACE ALL Col1 WITH STRTRAN(ALLTRIM(Col1),"651","652")  && Make everything starting with "651" begin with "652"

Good Luck,
JRB-Bldr


 
If you want to replace every instance of 651 with 652, then the following code will do it:

[tt]REPLACE ALL Column1 WITH STRTRAN(Column1, "651", 652")[/tt]

But be careful. That will replace 651, regardless of where it occurs within Column1. So if a given record contains XYZ651, you will end up with XYZ652. That might not be what you want.

If you want to replace the first three characters of Column1 with 652 in every record, then do the following:

[tt]REPLACE ALL Column1 WITH "652" + SUBSTR(Column1, 4)[/tt]

If neither of those is what you want, perhaps you could clarify your requirements.
Mike







__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Thank you gys, ultimately I found the "stuff" command to be the easiest to work with.

I appreciate everyone's feedback and insight. I'm a newbie to FoxPro so it's a little tricky. Slowly but surely i'm getting there.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top