Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
StrTran() - any known limitations?
Message
From
31/10/2007 13:08:33
Dragan Nedeljkovich (Online)
Now officially retired
Zrenjanin, Serbia
 
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Environment versions
Visual FoxPro:
VFP 9 SP1
OS:
Windows XP SP1
Miscellaneous
Thread ID:
01265319
Message ID:
01265434
Views:
17
>>Haven't played with RegExp for a while - and while this case doesn't really need
>>them (I'm replacing strings I've already found by StrExtract, or replacing single
>>characters), if oRx.Replace() is safer and not too much slower, I may give it a go
>>in the next iteration of this.
>
>I'd suggest using Craig Boyd's RegExp.fll, since it's much faster than the VBScript object, but since you said above that you're trying to replace newlines, I don't believe that will work.

Actually I'm trying to... here goes:

I have a file of any length, supposedly in a .csv format. The last field is a memo, delimited by ," on the left, and ", on the right. The field may contain any number of lf, crlf, crcrlf or other combinations (depending on whether the machine used to export it from sqlite is a Mac or a Win). The target is a .dbf table.

Of course, the record delimiter is a lf (or crlf), sooo... my first order of business is to do a

bigtext=filetostr("the.csv")

then go find those memos. This happens in a loop:

lcRepl=strextract(bigtext, [,"], [",]). Then

lcReplTo=strtran(lcRepl, chr(13)+chr(10), "{crlf}")
lcReplTo=strtran(lcReplTo, chr(13), "{cr}")
lcReplTo=strtran(lcReplTo, chr(10), "{lf}")
lcReplTo=strtran(lcReplTo, [""], "{qq}")
lcReplTo=strtran(lcReplTo, [,], "{comma}")
*-- and a few other transformations
Then,
bigtext=strtrtan(bigtext, lcRepl, lcReplTo)

Once done with the loop, I can split the bigtext into records using alines, then split each record into fields using alines(... ","), then the last field is my memo where I have to revert all the above {whatever} replacements into what they originally were.
The reason for this thread is that in some cases, the last line wouldn't touch bigtext. It would remain the same. I don't see how would strextract() yield something with a different case.

As I said, I'll investigate this - but later, presumably tonight.

back to same old

the first online autobiography, unfinished by design
What, me reckless? I'm full of recks!
Balkans, eh? Count them.
Previous
Reply
Map
View

Click here to load this message in the networking platform