edit to remove double quote in field
Brian K. White
brian at aljex.com
Wed Jul 24 15:29:33 PDT 2013
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 "e; 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"] = "'"
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 = "'" ; 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
More information about the Filepro-list
mailing list