Kinook Software Forum

Kinook Software Forum (https://www.kinook.com/Forum/index.php)
-   [VBP] General Discussion (https://www.kinook.com/Forum/forumdisplay.php?f=2)
-   -   Quoting problem or bug? (https://www.kinook.com/Forum/showthread.php?t=1383)

pjaquiery 12-05-2005 04:23 PM

Quoting problem or bug?
 
1 Attachment(s)
I'm using a JScript regex replace to provide a value in a step as:

['%str%'.replace (/L"([[^"]]+?)"/, '$1')]

which fails to match my test string L"wanted text". However:

['%str%'.replace (/L"(.+?)"/, '$1')]

matches as expected.

Is this a quoting problem that I've forgotten about, or is there something else going on here? A sample project is attached.

kinook 12-05-2005 09:56 PM

The behavior is by design. The order of processing of field values is:

Repeat 1a/b until no macro or script references remain:
1a) Expand macro references to the actual value. For instance %STR% -> L"wanted text" or %DOSCMD% -> %COMSPEC% /C

1b) Evaluate any script expressions (code between single bracket chars).

2) Convert any double bracket chars to single ([[ -> [ and ]] -> ]).

So at the point that the JScript expression is evaluated, the code that is fed to the script engine is

"'L"wanted text"'.replace(/L"([[^"]]+?)"/, '$1')"

The reason for processing in this order is to support nested script expressions and macros (script expressions and macros can expand to other scripts expressions and/or macros ad infinitum).

A couple alternatives:

1) Move the .replace code into a script function in Project or Global scripts and call it from the script expression.

2) Use a Run Script step instead of a Set Macro step (brackets aren't special in a Run Script step since the code field is already treated as script):

Application.Macros(vbldMacroTemporary).Add("Str", '%STR%'.replace(/L"([^"]+?)"/, '$1'));


All times are GMT -5. The time now is 02:20 PM.


Copyright © 1999-2023 Kinook Software, Inc.