NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

FindAndReplace What is the returned value

I have found a function used in some NI sample code FindAndReplace() and it doesnt show as a teststand function. Anybody used it or know what the return values are and any optional parameters ?
0 Kudos
Message 1 of 4
(3,142 Views)
FindAndReplace was obsoleted (ie. no longer documented) in favor of the nearly identical SearchAndReplace function. SearchAndReplace returns the modified string, which is more generally useful in expressions than the number-of-replacements, which is what FindAndReplace returns.
0 Kudos
Message 2 of 4
(3,142 Views)
Rupert -
In the TestStand expression language there is a SearchAndReplace function which returns the modified string. What is the code snippet, is it C, C++, expression?

Scott Richardson (NI)

SearchAndReplace(string, searchString, replacementString, , , , , )
This function searches for and replaces one or more substrings with the replacementString.
Parameter 1: A string in which to perform substring replacements.
Parameter 2: The substring to find and then replace with the replacement string.
Parameter 3: The replacement string.
Parameter 4: An optional number that specifies the zero-based character index at which to begin searching. The default is 0.
Parameter 5: An op
tional Boolean that specifies whether to ignore character case when searching. The default is False.
Parameter 6: An optional number that specifies the maximum number of occurrences of substring to replace. A value of -1 signals the function to replace all occurrences of the substring. The default is -1.
Parameter 7: An optional Boolean that specifies whether to search the string in reverse. The default is False. If you pass True, the start index passed to parameter 3 specifies the zero-based index from the end of the string of the character at which to begin searching in reverse.
Parameter 8: An optional number in which the function stores the number of substrings that it replaced.
Returns: The modified string.
Scott Richardson
0 Kudos
Message 3 of 4
(3,142 Views)
Just thought I would add one comment here. The SearchAndReplace() function has one undocumented feature that caused me some chagrin a few weeks ago.

If a simple variable is passed as the "string" parameter, then SearchAndReplace() will actually modify the string, and return a copy of it.

This seems to happen if the passed value is what in "C" would be called an "l-value". To prevent the original variable being modified, you can instead pass an expression that evaluates to an identical value. The result of an expression is not an l-value.

In my case, instead of passing Locals.ConnectionString, I passed Locals.ConnectionString+""

- Ron
0 Kudos
Message 4 of 4
(3,142 Views)