dbTalk Databases Forums  

Find and Replace a portion of a string

comp.databases.paradox comp.databases.paradox


Discuss Find and Replace a portion of a string in the comp.databases.paradox forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
JR
 
Posts: n/a

Default Find and Replace a portion of a string - 02-17-2006 , 01:28 PM






I have a custom Real Estate application I built in Pdox 10.0. I am
downloading 2 ascii text files and importing to separate tables. Each
is from a different source. One is tax roll data the other Multiple
Listing Data. I need to compare the 2 tables and the address fileds
have to be consistant to do so. In the MLS table, the address field
contains the house number, the street name and the designator (Rd, St,
Ln, Dr etc).
Some of the addresses in the MLS table have Drive, Street Lane etc. I
need to scan the table, locate the records that have the above
designators and then change them to Dr, St, Ln, etc. This will make
them consistant with the Tax roll data.
I'm guessing the logis is to locate the record with advMatch. Then get
the whole string, breakapart into an array, then put it back together
again with new designator. The challenge I'm having is: How do I
identify the last element of the array? For example the address could
be 123 Main Drive. It could also be 123 South Main Drive. The word
Drive is the 3rd element in the first example but the 4th in the
second. It's always the last.
Any help would be appreciated.
TIA
JR


Reply With Quote
  #2  
Old   
Liz McGuire
 
Posts: n/a

Default Re: Find and Replace a portion of a string - 02-17-2006 , 02:29 PM






var
ar Array[] String
endVar

ar[1] = "the first element"
ar[ar.size()] = "the last element"

Liz


JR wrote:
Quote:
How do I
identify the last element of the array?

Reply With Quote
  #3  
Old   
David Farmer
 
Posts: n/a

Default Re: Find and Replace a portion of a string - 02-18-2006 , 09:18 AM



But there is an easier way with advandMatch! If you give advMatch() more
arguments than just the match string, it will return the portions of the
string that match yours. For example, if you do advMatch() on the address
field of your table with the arguments like:

tCursor."Address Field".advMatch("^(..) (Lane)$",firstMatch,secondMatch),
you will have all of the address except for the "Lane" at the end in the
firstMatch variable and the Lane part in the secondMatch string. Then you
just have to add "Ln" on to the end of firstMatch and put that back in
tCursor."Address Field". Make advMatch() part of a switch for each case of
"Lane","Street","Road","Avenue" or whatever and tack on the appropriate
abbreviation and you're done! No breakapart or anything else. If you have
apartment no's or something as part of address, so that the street suffix
isn't always the last bit of the field, just put another (..) after the
suffix and catch it too, then knit together.

It easy! Lots easier than messing with arrays it seems to me.



Reply With Quote
  #4  
Old   
JR
 
Posts: n/a

Default Re: Find and Replace a portion of a string - 02-18-2006 , 12:36 PM



David,
Thanks for your suggestion.
I am just testing for now just so I can see if the concepts will work.
Here is the code I am currently trying but with no luck.
var
tc Tcursor
s,s1 String

endvar


tc.open(":Tables:MLSImport")

scan tc :
if tc."Address".advMatch("^(..)(Blvd)$") then ;testing for Blvd
s.view()
s1.view()
else
msgInfo("Hey","Can't find it")
return
endif

endscan

Continue getting the msgInfo portion, meaning the IF statement returned
false. Am I missing something?
Thanks for your help.
Jeff


Reply With Quote
  #5  
Old   
Jeff Revell
 
Posts: n/a

Default Re: Find and Replace a portion of a string - 02-20-2006 , 03:30 PM



Thanks David!
You are right about the "Return". That is stopping it from running the rest
of the table. I do get the msgInfo once.
I have not written the for each loop into my scripts or code because I am
just not 100% comfortable with my understanding of it.
I'll look at your code and see if I can learn more.
Thanks again.
Jeff

"David Farmer" <dafarmer (AT) hotmail (DOT) com> wrote

Quote:
That looks like it should work to me, except that you need to include the
"s" and "s1" strings in the argument for advMatch():
tc."Address".advMatch("^(..) (Blvd)$",s,s1). I alway put any spaces
before
"Blvd" between the first ")" and the following "(" of the halves of the
whole string OUTSIDE the parentheses so they won't be picked up as part of
the strings ... advMatch() seems to work better if there is SOMETHING
definite that seperates the two halves you want to split up ... are you
sure
the table is open like you think? You haven't tested it, but if your
logic
is correct, you should be getting either the view()'s or the msgInfo() for
EVERY record of the table the way this is written. What about writing a
bit
of test code that let's you enter an address and test your match arg in
advMatch() ... you could even make it so that you can enter the match arg
string interactively too ... get it working right for a string you KNOW
what
you put in and then use that arg for your table.

I attached a sample script to show you what I mean ... works on my Windows
98 machine running Paradox 10, but there's nothing I know of to stop it
from
running in almost any version of Paradox since version 5! Oh, I just
noticed .... on your code, you have a return inside the else of your if
statement ... that means, if advMatch() fails on the FIRST record of your
table, the code stops! Bet that's the trouble ... also explains why you
don't see msgInfo() for EACH record in your table (assuming you don't).






Reply With Quote
  #6  
Old   
Jeff Revell
 
Posts: n/a

Default Re: Find and Replace a portion of a string - 02-20-2006 , 04:03 PM



It worked like a champ. I modified it slightly and it performed flawlessly
and fast!
Thanks


"Jeff Revell" <Jeff (AT) JeffSellsBrandon (DOT) com> wrote

Quote:
Thanks David!
You are right about the "Return". That is stopping it from running the
rest of the table. I do get the msgInfo once.
I have not written the for each loop into my scripts or code because I am
just not 100% comfortable with my understanding of it.
I'll look at your code and see if I can learn more.
Thanks again.
Jeff

"David Farmer" <dafarmer (AT) hotmail (DOT) com> wrote in message
news:43f88d86 (AT) pnews (DOT) thedbcommunity.com...
That looks like it should work to me, except that you need to include the
"s" and "s1" strings in the argument for advMatch():
tc."Address".advMatch("^(..) (Blvd)$",s,s1). I alway put any spaces
before
"Blvd" between the first ")" and the following "(" of the halves of the
whole string OUTSIDE the parentheses so they won't be picked up as part
of
the strings ... advMatch() seems to work better if there is SOMETHING
definite that seperates the two halves you want to split up ... are you
sure
the table is open like you think? You haven't tested it, but if your
logic
is correct, you should be getting either the view()'s or the msgInfo()
for
EVERY record of the table the way this is written. What about writing a
bit
of test code that let's you enter an address and test your match arg in
advMatch() ... you could even make it so that you can enter the match arg
string interactively too ... get it working right for a string you KNOW
what
you put in and then use that arg for your table.

I attached a sample script to show you what I mean ... works on my
Windows
98 machine running Paradox 10, but there's nothing I know of to stop it
from
running in almost any version of Paradox since version 5! Oh, I just
noticed .... on your code, you have a return inside the else of your if
statement ... that means, if advMatch() fails on the FIRST record of your
table, the code stops! Bet that's the trouble ... also explains why you
don't see msgInfo() for EACH record in your table (assuming you don't).








Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.