07-07-2017 09:52 AM
I've noticed that the formula substitution VI appears to treat underscores as whitespace. For example, attempting to substitute "XXX_YYY" for "x" in any formula containing "XXX_YYY" will fail resulting in no substitutions. Substituting "XXX" for "x" in the same formula will result in "(x)_YYY".
This is not documented anywhere and seems counter-intuitive given that underscore characters are normally considered "Word characters".
Has anyone else noticed this and is there a way to override this behavior?
07-07-2017 10:14 AM
I assume you are using "Substitute Variables.vi"
I looked through, and it seems the way this vi works is to split the formula into parts using the type of characters. For example, all upper/lower case are the only ones to be checked for substitution.
The way it does this is using the "Lexical Class Function". Unfortunately the underscore is in the same class as all the mathematical operators, so the vi sees this as separating two variables just like an minus character would.
That is why it happens. To fix this, you would have to edit the subVI "Find String Identifier" to ignore underscores.
I have no experience with this function palette, but I imagine you could just replace this function with a carefully configured "search and replace string", which should have no issues with underscores. The only possible issue here is if you have variables which are string subsets of another variable. For example if you had AA and also AAA. The substitute variables handles this already.
07-07-2017 11:38 AM
That's what I was afraid of. I think what I can likely do is pre-process my formulas to simply remove the underscores.
04-24-2020 08:02 PM
Yup. I had the same issue. I stripped out the underscore characters from both the array of user names in the substitution rule array as well as the underscores in the particular string being substituted. See attached .PNG. (The VI in the png is a functional global variable that stores the three arrays: a user name string array, LabView's string array (the a0, a1, ... through z9 allowed names), and the actual numeric value for each variable.) You can use as many underscores as you want including one or more leading, trailing and in-line underscores.