Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to replace text "within" text in a character field

0 views
Skip to first unread message

ksa...@my-dejanews.com

unread,
Jul 14, 1998, 3:00:00 AM7/14/98
to
Hello,

I'm a non-programmer who's got some intermediate experience with FP 2.6/Win
and was recently upgraded to VFP 5.0a. I'm trying to replace every
occurrence of "P.O." or "PO" with "P. O." and "Street" with "St." in an
address field.

I know this is basic stuff for you guys, but I am frustrated as heck at not
being able to find any material that explains how to do this. I've tried using
VFP Help, but can't seem to figure which function or command to use and how to
code it.

The table name is d_master and the field name is m_address1

I've tried:
REPLACE ALL d_master.m_address1 WITH "P. O." FOR d_master.m_address1="P.O."
REPLACE ALL d_master.m_address1 WITH "P. O." FOR
d_master.m_address1=SUBSTR("P.O.",4)

STRTRAN(d_master.m_address1,"P.O.","P. O.")


I've also fooled around with LOCATE and AT, but I couldn't even get them to
find the first occurrence of the text.

PS. Is there a book that explains how to use FoxPro commands and functions
with various "real world" examples that would help a novice like me? Or is
there a or FAQ file, web site, mail list, or newsgroup for FoxPro novices?

Thanks,

ks

-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/rg_mkgrp.xp Create Your Own Free Member Forum

Loris Antonangeli

unread,
Jul 14, 1998, 3:00:00 AM7/14/98
to ki...@mlc.lib.ms.us
ksa...@my-dejanews.com wrote:
>
> Hello,
>
> I'm a non-programmer who's got some intermediate experience with FP 2.6/Win
> and was recently upgraded to VFP 5.0a. I'm trying to replace every
> occurrence of "P.O." or "PO" with "P. O." and "Street" with "St." in an
> address field.
>
> I know this is basic stuff for you guys, but I am frustrated as heck at not
> being able to find any material that explains how to do this. I've tried using
> VFP Help, but can't seem to figure which function or command to use and how to
> code it.
>
> The table name is d_master and the field name is m_address1
>
> I've tried:
> REPLACE ALL d_master.m_address1 WITH "P. O." FOR d_master.m_address1="P.O."
> REPLACE ALL d_master.m_address1 WITH "P. O." FOR
> d_master.m_address1=SUBSTR("P.O.",4)
>
> STRTRAN(d_master.m_address1,"P.O.","P. O.")
>
> I've also fooled around with LOCATE and AT, but I couldn't even get them to
> find the first occurrence of the text.
>
> PS. Is there a book that explains how to use FoxPro commands and functions
> with various "real world" examples that would help a novice like me? Or is
> there a or FAQ file, web site, mail list, or newsgroup for FoxPro novices?
>
> Thanks,
>
> ks
>

Try this:


REPLACE ALL;
d_master.m_address1 WITH STRTRAN(d_master.m_address1,"P. O.","P.O.")
REPLACE ALL;
d_master.m_address1 WITH STRTRAN(d_master.m_address1,"Street","St.")

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Loris Antonangeli, University of Oulu (Finland)
phone: +358-8-5565456, +358-40-5015645
e-mail: lo...@cc.oulu.fi
http://cc.oulu.fi/~loris/loris.htm

Messages FOR FREE straight to my GSM-phone - follow instructions:
1) Go to http://www.mtn.co.za/regulars/sms/,
2) Choose Network "Finland Telecom Finland / Sonera 35840"
3) Enter my gsm-phone number +358405015645
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Ennen olin epävarma - nyt en oikein tiedä...

Geoff Davison

unread,
Jul 14, 1998, 3:00:00 AM7/14/98
to
Hi

Try

REPLACE ALL d_master.m_address1 WITH STRTRAN(d_master.m_address1, "P.O.",
"P. O.")
REPLACE ALL d_master.m_address1 WITH STRTRAN(d_master.m_address1, "PO.", "P.
O.")
REPLACE ALL d_master.m_address1 WITH STRTRAN(d_master.m_address1, "Street.",
"St.")


Be careful though as it will replace these characters even if they are in
the middle of a word

eg. "POINDEXTER PLACE" would become "P. O.INDEXTER PLACE"

to trap for whole words include a space either side of the search string.
Note however this will miss lines that begin with the seach expression.

Also note that strtran is case sensitive so to trap for all eventualities
you need to repeat the process several times unless you are happy to convert
everything into uppercase.

You could write something more advanced to trap for several diferent
spellings and make sure that it was a whole word only and call it as a
function but this would be slower.

Geoff Davison

use...@xxxmastersystemsxxx.co.uk

For genuine e-mail from news groups please remove all the xxx's before
replying

Myron Kirby

unread,
Jul 14, 1998, 3:00:00 AM7/14/98
to
Only thing I would add to Loris solution is to add a space after and before
'Street'. This will avoid accidental changing any word that contains
street.

REPLACE ALL;
d_master.m_address1 WITH STRTRAN(d_master.m_address1,"P. O.","P.O.")

REPLACE ALL;
d_master.m_address1 WITH STRTRAN(d_master.m_address1," Street "," St. ")


-myron kirby-
Independent Consultant
myr...@flash.net
===========================


Loris Antonangeli wrote in message <35AB8C58...@cc.oulu.fi>...


>ksa...@my-dejanews.com wrote:
>>
>> Hello,
>>
>> I'm a non-programmer who's got some intermediate experience with FP
2.6/Win
>> and was recently upgraded to VFP 5.0a. I'm trying to replace every
>> occurrence of "P.O." or "PO" with "P. O." and "Street" with "St." in an
>> address field.
>>
>> I know this is basic stuff for you guys, but I am frustrated as heck at
not
>> being able to find any material that explains how to do this. I've tried
using
>> VFP Help, but can't seem to figure which function or command to use and
how to
>> code it.
>>
>> The table name is d_master and the field name is m_address1
>>
>> I've tried:
>> REPLACE ALL d_master.m_address1 WITH "P. O." FOR
d_master.m_address1="P.O."
>> REPLACE ALL d_master.m_address1 WITH "P. O." FOR
>> d_master.m_address1=SUBSTR("P.O.",4)
>>

>> STRTRAN(d_master.m_address1,"P.O.","P. O.")
>>

>> I've also fooled around with LOCATE and AT, but I couldn't even get them
to
>> find the first occurrence of the text.
>>
>> PS. Is there a book that explains how to use FoxPro commands and
functions
>> with various "real world" examples that would help a novice like me? Or
is
>> there a or FAQ file, web site, mail list, or newsgroup for FoxPro
novices?
>>
>> Thanks,
>>
>> ks
>>
>
>
>
>Try this:
>
>

>REPLACE ALL;
> d_master.m_address1 WITH STRTRAN(d_master.m_address1,"P. O.","P.O.")
>REPLACE ALL;

Gene Wirchenko

unread,
Jul 14, 1998, 3:00:00 AM7/14/98
to
"Myron Kirby" <myr...@flash.net> wrote:

>Only thing I would add to Loris solution is to add a space after and before
>'Street'. This will avoid accidental changing any word that contains
>street.

I'd include some sort of confirmation or review. In Toronto, ON,
there is an "Avenue Road". In Coquitlam, BC, there is a "North Road".

Sincerely,

Gene Wirchenko

Computerese Irregular Verb Conjugation:
I have preferences.
You have biases.
He/She has prejudices.

ksa...@my-dejanews.com

unread,
Jul 14, 1998, 3:00:00 AM7/14/98
to
Thanks,

That did it!

ks

In article <6og475$g3t$1...@heliodor.xara.net>,
"Geoff Davison" <use...@xxxmastersystemsxxx.co.uk> wrote:

> Try
>
> REPLACE ALL d_master.m_address1 WITH STRTRAN(d_master.m_address1, "P.O.",
> "P. O.")
(clip)


> Be careful though as it will replace these characters even if they are in
> the middle of a word
>
> eg. "POINDEXTER PLACE" would become "P. O.INDEXTER PLACE"
>
> to trap for whole words include a space either side of the search string.
> Note however this will miss lines that begin with the seach expression.
>

-----== Posted via Deja News, The Leader in Internet Discussion ==-----

Brett Slattery

unread,
Jul 15, 1998, 3:00:00 AM7/15/98
to
Adding to other posts,

It's helpful to consider the placement of the <string to be replaced>.
In other words, don't replace St. unless its the last 2 characters of the
string.
Don't replace <PO or upper(P.O.)> unless its the beginning of the string.


--
Brett Slattery
Slat...@ewol.com

ksa...@my-dejanews.com wrote in message
<6og03a$tkf$1...@nnrp1.dejanews.com>...


>Hello,
>
>I'm a non-programmer who's got some intermediate experience with FP 2.6/Win
>and was recently upgraded to VFP 5.0a. I'm trying to replace every
>occurrence of "P.O." or "PO" with "P. O." and "Street" with "St." in an
>address field.
>
>I know this is basic stuff for you guys, but I am frustrated as heck at not
>being able to find any material that explains how to do this. I've tried
using
>VFP Help, but can't seem to figure which function or command to use and how
to
>code it.
>
>The table name is d_master and the field name is m_address1
>
>I've tried:
>REPLACE ALL d_master.m_address1 WITH "P. O." FOR d_master.m_address1="P.O."
>REPLACE ALL d_master.m_address1 WITH "P. O." FOR
>d_master.m_address1=SUBSTR("P.O.",4)
>

>STRTRAN(d_master.m_address1,"P.O.","P. O.")
>
>

>I've also fooled around with LOCATE and AT, but I couldn't even get them to
>find the first occurrence of the text.
>
>PS. Is there a book that explains how to use FoxPro commands and functions
>with various "real world" examples that would help a novice like me? Or is
>there a or FAQ file, web site, mail list, or newsgroup for FoxPro novices?
>
>Thanks,
>
>ks
>

Brett Slattery

unread,
Jul 15, 1998, 3:00:00 AM7/15/98
to

Gene Wirchenko

unread,
Jul 15, 1998, 3:00:00 AM7/15/98
to
"Brett Slattery" <slat...@ewol.com> wrote:

>Adding to other posts,
>
>It's helpful to consider the placement of the <string to be replaced>.
>In other words, don't replace St. unless its the last 2 characters of the
>string.

What about if there is a directional suffix as in "123 Main
Street West"?

>Don't replace <PO or upper(P.O.)> unless its the beginning of the string.

What about "Box 123, Main PO"?

[snip]

Chris Kefel

unread,
Jul 20, 1998, 3:00:00 AM7/20/98
to
If you're using STRTRAN(d_master.m_address1,"P.O.","P. O."), use it in
combination with the replace command :
- replace d_master.m_address1 with STRTRAN(d_master.m_address1,"P.O.","P.
O.")
- replace all d_master.m_address1 with

STRTRAN(d_master.m_address1,"P.O.","P. O.")
- replace d_master.m_address1 with STRTRAN(d_master.m_address1,"P.O.","P.
O.") for ...

Greatings,

0 new messages