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!

FoxPro Search and Replace Problem 1

Status
Not open for further replies.

noahldavis

Programmer
Mar 9, 2011
3
US
In a memo field, I have date strings that are listed like
3.9.10 or
3.9.2011 or
11.15.10 etc.
which can appear multiple times in multiple forms in a single memo field.

I need to change those periods "." to slashes "/".

Can anyone give me an easy way to do this?

Thanks.
 
Sorry - didn't communicate clearly. These dates are in long memo fields and periods are everywhere, as the notes contain sentences. I can't just change all the periods to slashes. (That even in my limited capacity I know how to do.) I was looking for a way to search for the string nn.nn.nn (where n is any integer) and replace just those periods between numbers with slashes.

Thanks.
 
"I need to change those periods "." to slashes "/"."

"I can't just change all the periods to slashes."

Well we can only assume that you can define the specific criteria where you DO want to change the periods to slashes.

If so, they add that selective criteria to your STRTRAN() or CHRTRAN() command. Look into your VFP Help for more info on those functions.

Example: REPLACE ALL MemoData WITH STRTRAN(MemoData,"abc.def.xyz","abc/def/xyz")

Also note that where n is any integer is NOT an Integer when it appears in a Memo field. Instead it is a Character which represents an integer.

Good Luck,
JRB-Bldr

 
Thanks JRB-Bldr. That's very helpful. I appreciate it.
 
The pattern you're looking for is something like this:

(one or two digits).(one or two digits).(exactly two digits)

Right? That's a Regular Expression, and the FFC contains a class that exposes a RegExp engine. Google "VFP Regular Expression" if you need help ... there's tons of it out there.

What you're going to have to do is process each memo field, passing each 10-byte string contained in the memo field through a RegExp comparison to see if you've found a date, then StrTran() only that portion of the string.

You'll want to work in memory because it will be faster and will diminish the memo bloat that naturally occurs each time a memo field is edited. This is "thinking out loud" prototyping:

Code:
lcField = theMemo
For lnCount = 1 to Len(lcField)-10
  lcString = Substr(lcField,lnCount,10)
  If YourRegExpFunction()
     * Found one! Doctor lcField
  Endif
Endfor
Replace theMemo with lcField

 
You'll want to work in memory because it will be faster and will diminish the memo bloat that naturally occurs each time a memo field is edited."

A solution to this situation is when done PACK the table and the bloat will be gone.

BTW: I have started to use this technique. I have one and only one table in my database (I use the term database lossely as I do not use a DBC, my database is the collection of free tables that make up the application's data. ) that has a memo field. It is the Notes table. It also has a field name "Note_Frag" (Fragment) a Character 100 field. When a note is <101 characters it goes into the Note_Frag, otherwise the full memo is used also. (There are several other fields such as a PK, Master_Table_Name, Note_Name etc. )

So far 90+ of the time the Note_Frag is used and therefore the actual Memo information is keep shall we say cleaner.

The 100 characters is a number that seemed best for the apps I am working with, other apps might find 50 or 250 or ?? a better fit. Basically I am finding the majority of the information in the apps I am working in a memo field to be < 100 characters, thou there is that <<1% that are 100,000 characters.

I have been using this idea for a couple of years and while there is a little more programming to start with I find the benifits are great.

-In many cases I may need a copy of the main table data, but no need for the memo, e.g. faster transfer times

-If the memo becomes corrupted I have at least the Fragment information.

-I can display to the user the Fragment information in a grid a little easier then having it in a memo

-Total file size is smaller (Less Memo Bloat)

-Only one table to pack to remove memo bloat if needed.

-Yes it does make SQL selects more complex and possibly slower but on the other hand if the Select does not need the memo information they an execute faster

Lion Crest Software Services
Anthony L. Testi
President
 
Most Regexp engines allow a replace, and global checking

Code:
lcString1 = "1.5.94     01.07.99"
oRE = CREATEOBJECT("VBSCRIPT.REGEXP")
oRE.Pattern = "(\d{1,2})\.(\d{1,2})\.(\d{2})"
oRE.Global = .T.

lcString2 = oRE.Replace( lcString1, "$1/$2/$3" )
 
The pattern described should probably change to:
Code:
oRE.Pattern = "\b(\d{1,2})\.(\d{1,2})\.(\d{2}(\s{2})?)"

which allows for 4 digit dates as well
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top