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!

Need to adjust a character in a string

Status
Not open for further replies.

TreizeRXH

MIS
Sep 17, 2015
6
US
I have a table in foxpro that I need to update for one column (called market).

In column "Market", there are entries that all follow the same naming convention: a 2 letter code plus numbers (i.e. AB115)

I need to make an adjustment to all these codes so that the 115 says 116 (AB115--> AB116)and that this change replicates across all the other lettered markets

I've tried using STRTRAN('115', '5', '6') but found that it ends up replacing everything with JUST 116. (i.e. AB115 ---> 116, which is wrong).

What do I need to do so that I retain the letter coding and also swap out the 115 for a 116? There are thousands of entries so doing each code invidually will be time consuming.

Any help is much appreciated!
 
As a demo of how STRTRAN works, do this
[tt]? STRTRAN("AB115","115","116")[/tt]

Now [tt]REPLACE market WITH STRTRAN(market,"115","116")[/tt]

You want to replace every 115 with 116, not every 5 with 6. This is not about a regexpression pattern, this is simple straight forward substring replacement, any 115 is turned to a 116, no matter what two letters are prefixed.

STRTTRAN("115","5","6") is not taking in anything from the table, so it always replaces the 5 in "115" with the 6 and ends in "116", yes. If you want somethiing to happen with the market field, it HAS to be part of the expression, part of the code, doesn't it have to?

Bye, Olaf.

 
Yes, Olaf, that worked perfectly! Dave I didn't get to try yours but I think I know what it's doing there.

Thank you again everyone for the quick responses, I appreciate it!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top