edit to remove double quote in field

brian at aljex.com brian at aljex.com
Wed Jul 24 18:57:33 PDT 2013


Stupid email... Or maybe just stupid web mail...

The code below may not be displaying to you the way I wrote it thanks to the email client rendering the "html entities" into the characters they stand for instead of the code I actually wrote. Which makes entirely all the difference in the world in this case since that's the entire damned point is to show code that handles and transforms exactly those characters... 

I wrote:
" & q u o t e ; "

and instead it's displaying
" " "

So here is the same lines with spaces inserted. You have to remove the spaces.

If: ac = "34"
Then: oc = " & q u o t e ; " ; goto ent2
If: ac = "38"
Then: oc = " & a m p ; " ; goto ent2
If: ac = "39"
Then: oc = " & a p o s ; " ; goto ent2
If: ac = "60"
Then: oc = " & l t ; " ; goto ent2
If: ac = "62"
Then: oc = " & g t ; "

-- 
bkw


-----Original Message-----
From: "Brian K. White" <brian at aljex.com>
Sent: Wednesday, July 24, 2013 6:29pm
To: filepro-list at lists.celestial.com
Subject: Re: edit to remove double quote in field

On 7/22/2013 12:31 PM, tob at b-e-s-t.com wrote:
>
> Is there an filepro edit to remove a double quote?
> tfxobrien at gmail.com


Not that I ever found.

The best I've been able to do is one of two things depending on the 
needs of the moment. One way is fast and cpu-cheap, but also crude and 
not good enough for many situations. The other way is good but you have 
to use it carefully to avoid unnecessarily bogging down your machine.

quick & dirty way, use xlate, either to swap the " with something else 
like ' or space or just delete it. This just deletes "

n = xlate(1,chr("34"),"")

Although I prefer to put this kind of thing in a gosub so I can do more 
than one thing and not have to rewrite it 500 times in a table.

n=1 ; gosub clean ; csv(1)=n
clean:
n = xlate(n,chr("34"){chr("13"),"'") ; return

In this example, " are turned to ' and carriage returns are just removed.



When you need better results than dumbly erasinging parts of the data, 
make a gosub that walks through every character in the input variable 
and builds up a new output variable, performing whatever tests and 
conversions you need along the way. Although the gosub can be 
complicated to get it working right, once you have it it's painless to 
use it 500 times in the table.

In a case where I need to convert " to &quote; and a few other similar 
traslations for an export to xml:

' just once!
gosub init

' any number of times
n = "something" ; gosub ent ; something = n

ent:
If: '*** escape the 5 special xml character entities ****************
Then: ' 
http://en.wikipedia.org/wiki/List_of_XML_and_HTML_character_entity_references
If: ' Read N and replace it with an xml-safe version
Then:
If: ' in       out       position   length
Then: di = n ; do = "" ; dp = "1" ; dl = len(di)
ent1:
If: ' inchar                outchar   asciichar
Then: ic = mid(di,dp,"1") ; oc = ic ; ac = asc(ic)
If: ",34,38,39,60,62," co ","{ac{","
Then: oc = xce[ac]
If:
Then: do = do & oc
If: dp lt dl
Then: dp = dp + "1" ; goto ent1
If:
Then: n = do
If:
Then: return

init:
If:
Then: dim xce(62)
If:
Then: xce["34"] = """
If:
Then: xce["38"] = "&"
If:
Then: xce["39"] = "&apos;"
If:
Then: xce["60"] = "<"
If:
Then: xce["62"] = ">"
If:
Then: return


So, the usage is still easy, just:
n = "something" ; gosub ent ; something = n

But "ent" is walking through every single character in "n" and 
performing several possible tests and actions on each one.

You have to be aware that that adds up to a lot of cpu work fast.

So you have to be careful to keep the loop in ent as small as possible. 
That's why I have it using an array in this case instead of a sequence 
of 5 separate if statements. In this example with only 5 possible 
checks, it probably hardly makes a difference. Although another way to 
look at it is I traded 5 tests for 2, which is 150% or so. And I 
carefully only load that array one time, outside of "ent" instead of 
doing it within "ent" where it would happen every time the gosub is 
used. Then again, I haven't timed it, but the 5 searate if statements 
would each be simpler, they would just be testing if a single byte = 
another single byte. Whereas the test above is a complex substring 
string "contains" comparison. Filepro itself might be working so much 
harder internally on that single line of code that maybe the 5 if: 
statements might actually be faster in this case. But if I wanted to add 
any more characters to this list, the array almost certainly becomes faster.

The simpler way with If: statements instead of a translation array would 
look like this just for reference and comparison. No init, it's all in ent:

ent:
If: '*** escape the 5 special xml character entities ****************
Then: ' 
http://en.wikipedia.org/wiki/List_of_XML_and_HTML_character_entity_references
If: ' Read N and replace it with an xml-safe version
Then:
If: ' in       out       position   length
Then: di = n ; do = "" ; dp = "1" ; dl = len(di)
ent1:
If: ' inchar                outchar   asciichar
Then: ic = mid(di,dp,"1") ; oc = ic ; ac = asc(ic)
If: ac = "34"
Then: oc = """ ; goto ent2
If: ac = "38"
Then: oc = "&" ; goto ent2
If: ac = "39"
Then: oc = "&apos;" ; goto ent2
If: ac = "60"
Then: oc = "<" ; goto ent2
If: ac = "62"
Then: oc = ">"
ent2
If:
Then: do = do & oc
If: dp lt dl
Then: dp = dp + "1" ; goto ent1
If:
Then: n = do
If:
Then: return

-- 
bkw
_______________________________________________
Filepro-list mailing list
Filepro-list at lists.celestial.com
Subscribe/Unsubscribe/Subscription Changes
http://mailman.celestial.com/mailman/listinfo/filepro-list







More information about the Filepro-list mailing list