The Hackers Guide says a double ampersand (&&) can be used at any point in a line - to start a comment. I might add even in the middle of a quoted string!
In the middle of an import I got a "Command contains unrecognized phrase/keyword" error. The line:
REPLACE stringfield WITH "OFF &&&&&&&&&" IN tablename
The solution is to do a strtran on the string before the REPLACE:
lcTemp = strtran(lcTemp, "&" + "&", [" + "&" + "&" + "])
The double ampersand is converted to a concatenated double ampersand in the middle of lcTemp. Note the concatenated double ampersand in the second parm to 'strtran'. You must do this or you'll cause the error yourself!
lcString = "&&"
lcString = "&" + "&"
The first line is not a valid line of code. The second is. I find it surprising the parser looks for && first, over and above quoted strings.
Note the Wiki handles this correctly! I wonder if the Wiki does anything special to handle double ampersands.
#FB I'm not so sure why the Wikis would need to do anything special for &&. Just like putting && in a table's field, it doesn't make a difference. The only time it matters is when the compiler hits it in code. -- Mike Helland
Yes. I should have included the context:
lcSql = "REPLACE " + lcField + " WITH '" + lcValue + "' IN " + lcTable
Actually ended up doing this:
do while at("&"+"&", lcTemp) > 0
lcTemp = strtran(lcTemp, "&" + "&", [&])
to avoid adding chars to lcTemp which is going to a fixed length string field. I don't want to add chars because I might push some other data past the end of the string field thereby losing data in the REPLACE. In this case, I lose ampersands but they're not significant in the source system.
[2001.11.26 12:29:44 PM EST]
Also, you can use
CHR(38) + chr(38) as well. Doug Dodge
I still wasn't happy with losing ampersands so I came up with the simpler:
lcTemp = CHR(38) + chr(38)
replace (lcField) with lcTemp in (lcTable)
which works just fine. Next time I'll resolve completely, then post. Joe Kuhn
Contributor: Joe Kuhn
Category VFP Tips And Tricks
( Topic last updated: 2005.08.19 02:17:14 PM )