05-28-2013 10:07 AM
Hi,
I am trying to use the "Format Into String" function to edit a string with multiple format arguments. However, I do not know the number of arguments in the string beforehand. The posted png below shows the exemplary case of three arguments and accordingly three values they are to be replaced with. The vi certainly won't run like that, since the "Format Into String" function only works when its no. of inputs matches the no. of arguments.
My idea now was to split the input string after each format argument, then feed the separate string parts to the function, and finally reassemble the strings again. Is there a nice way to identify format arguments in a string, such that I can then use the offset (or whatever else the output may be) to divide the input string into individual parts with only one argument each? I could of course make a list of possible format codes to search for (%.d, %.2f, %.;%.8f; %<%Y-%m-%d>T, ...), which would be really unaesthetic and also error-prone, so I'd like to find another way.
Best regards
05-28-2013 10:15 AM
What about this?
05-28-2013 10:22 AM
Thanks for the fast reply didje007,
maybe I oversimplified the example. Of course your solution works - if the number of arguments in the input string is known. The "General SQL operation" string is actually an input with a variable number of arguments. So I'd have to adjust the number of inputs on the "Format Into String" function programatically, which - as far as I know - is not possible.
05-28-2013 10:38 AM
You can specify the number to be used in a different order for exemple %2$ %1$.
For example your 1st parameter is always min, your 2nd is always max and the 3rd is always date.
Then you can write queries templates where you specify which parameter to use in which order....
For example Select* from data WHERE time < %3$ AND B<%2$
This function does not use the first string.
Then you can have less format specifier in your string than you have inputs to your format into string
05-28-2013 11:14 AM
Thanks for the tip on the "Format Into String". I didn't know that you could use the arguments in any order. Very useful!
05-28-2013 11:42 AM - edited 05-28-2013 11:46 AM
05-29-2013 02:45 AM
Thanks for your replys already,
jcarmody's answer goes in the right direction. But let me give you yet another, more general picture. Looks like you didn't quite get what I was trying to ask. Sorry for the lack of clarity.
I have a string array with SQL commands (which are known to me) where the limiting values in each where-clause are variables (which are specified by the user and thus not know to me). I am trying to find a way to integrate the user-specified values into each of the strings to finally get a specific SQL command.
I could of course, as the general commands are known to me, simply use a case structure for each of them and then accordingly convert them. However, to make the program easily extendible, I am trying to find a more general solution. Basically the problems boils down to what jcarmody manually did: Is there a way to identify and locate the different format codes in a string? This would make it possible to turn each string into an array and then use jcarmody's code.
Simply looking for the %-sign and the subsequent space won't work, take for example the cases "%<%Y-%m-%d %H:%M:%S>T" or "%,;%.3f". Actually the functionality I'm asking for here is locked somewhere in the "Format Into String" VI, which recognizes format codes in an input string.
Thanks again and best regards
05-29-2013 05:26 AM
Well I think you're going to have to use "Scan string for tokens" (or other suitable replacement) to extract somehow the location of the formatters for your values, split the formatting string into an array of strings with a single formatter each and then feed the results into a for loop with the results for each string operation being concatenated at the end.
I currently don't see a way of doing this properly without working on the formatting string somehow.
Shane.
05-29-2013 05:38 AM
I'm wondering how the black box is to know what each of those doubles represents. You have three doubles in the bottom element; how should a VI determine that those should be DELETEd instead of SELECTed?
05-29-2013 06:04 AM
@jcarmody wrote:
I'm wondering how the black box is to know what each of those doubles represents. You have three doubles in the bottom element; how should a VI determine that those should be DELETEd instead of SELECTed?
Due to the order of the % formatters occurring in the associated formatting string.......