LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

"Format into string" with a variable no. of inputs

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.

 

 

Create SQL command.png

 

Best regards

0 Kudos
Message 1 of 13
(5,386 Views)

What about this?

0 Kudos
Message 2 of 13
(5,381 Views)

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.

0 Kudos
Message 3 of 13
(5,374 Views)

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

 

Format.png

 

 

 

Message 4 of 13
(5,361 Views)

Thanks for the tip on the "Format Into String".  I didn't know that you could use the arguments in any order.  Very useful!

0 Kudos
Message 5 of 13
(5,349 Views)

I don't know how you'd know the arguments at run-time, so I assumed this:

 

Example_VI.png

Jim
You're entirely bonkers. But I'll tell you a secret. All the best people are. ~ Alice
For he does not know what will happen; So who can tell him when it will occur? Eccl. 8:7

Message 6 of 13
(5,338 Views)

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.

 

Create SQL command.png

 

Thanks again and best regards

0 Kudos
Message 7 of 13
(5,294 Views)

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.

0 Kudos
Message 8 of 13
(5,286 Views)

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?

Jim
You're entirely bonkers. But I'll tell you a secret. All the best people are. ~ Alice
For he does not know what will happen; So who can tell him when it will occur? Eccl. 8:7

0 Kudos
Message 9 of 13
(5,281 Views)

@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.......

0 Kudos
Message 10 of 13
(5,274 Views)