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!

change a word in a field

Status
Not open for further replies.

Siddiq

MIS
Sep 23, 2000
46
0
0
PK
Dear friends

I want to change a word like MALE to FEMALE in a particular field of my database. Please remember the field size is 80 and the word might be at any positon. How to replace it in the all records of database ?

Thanks
 
Code:
** If you want to change MALE to FEMALE
REPLACE YourField WITH STRTRAN(YourField,[ MALE ],[ FEMALE ]) ALL

** If you want to Reverse the field contents:
1. REPLACE YourField WITH STRTRAN(YourField,[ FEMALE ],[ MYFEMALE ]) ALL
2. REPLACE YourField WITH STRTRAN(YourField,[ MALE ],[ FEMALE ]) ALL
3. REPLACE YourField WITH STRTRAN(YourField,[ MYFEMALE ],[ MALE ]) ALL

(not tested well)

Borislav Borissov
 
Hi Borislav,

I also haven't tested, but this surely will have problems with fieldvalues starting "MALE ...". But without the spaces around MALE and FEMALE it would even be worse:

FEMALE->MYFEMALE->MYFEFEMALE

Like always, FEMALES are harder to deal with, especially if you want to make them your own ;-).

By the way, Siddiq, [] are string delimiters too, like ' and ".

If you want values LIKE "MALE %" or LIKE "% MALE" to be translated to "FEMALE %" / "% FEMALE" respectively, you'd need all these three REPLACEs:

Code:
REPLACE YourField WITH STRTRAN(YourField,[MALE ],[FEMALE ]) ALL
REPLACE YourField WITH STRTRAN(YourField,[ MALE ],[ FEMALE ]) ALL
REPLACE YourField WITH STRTRAN(YourField,[ MALE],[ FEMALE]) ALL
It's important that the replacement of [MALE ] is done first, or else you'd end up with FEFEMALE. You'd very seldom have the situation with [ MALE], as that would mean the field length is used fully and the value ends with MALE. Then you'd surely end up with [%FEMA].

Bye, Olaf.
 
Nonsense.

That's better (with FOR-Clauses):
Code:
REPLACE YourField WITH STRTRAN(YourField,[MALE ],[FEMALE ]) for LIKE("MALE*",Yourfield)
REPLACE YourField WITH STRTRAN(YourField,[ MALE ],[ FEMALE ]) ALL
REPLACE YourField WITH STRTRAN(YourField,[ MALE],[ FEMALE]) for LIKE("*MALE",Yourfield)

Bye, Olaf.
 
Thanks friends.

I applied STRTRAN and it is working perfectly ... once again thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top