LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Best source of string formatting examples? (NOT LV help please)

Forgive my ignorance if I am wrong but I am not happy with the Labview help reference when it comes to explaining string formatting functions in general.
LV has powerful timesaving string formatting functuions and yet real help in this area is very limited and has not changed since the beginning.

I am particularly annoyed with the lack of meaningful examples on the following functions.

match pattern
Search and replace string
Search and replace pattern
Scan string for tokens

I am aware of "Match pattern details"
and "special characters" in the LV help but it is at best (IMHO) flimsy and no other reference I am awarwe of.

I thus spend a lot of time trying to understand these cryptic explanations when a few (more than one) real world examples
would have me on my way, a happy camper.

Are there more illuminating examples of LV string formatting somewhere?
Message 1 of 12
(3,163 Views)
You are not alone. I've been working with Labview for about 5 years now and I still have some trouble with the formatting functions. I agree that the examples and explanations are flimsy. NI needs to improve on this subject. I have had to learn about some formatting from co-workers and this forum. Here is one instance that drove me nuts:
I have a comma delimited string that contains words and numbers. I wanted to use the spreadsheet string to array to transform the input string into arrays of strings and numbers. Here is an example string with the data types that I needed to be converted in parenthesis:
Resistance Test (string), Comment String (string), 5 (U16), 0 (U16), 10 (U16)
My data file contains many lines of strings like the above representing the test name, comment, measurement, lower and upper limits. I tried using a format string of something like %s,%s,%d,%d,%d. What happens is that the first %s reads "Resistance" and because of the space between "Resistance" and "Test", "Test" was taken to be the second %s. It would bomb on the first %d. What finally worked was a format string of just "%d". Somehow the outputs came out right, 2 word string-2 word string-number-number-number. Doesn't make any sense to me. What if I had DBL instead of U32? Would I use just "%.2f"? The above example is very common in testing, in one form or another. It would be nice to have a help screen showing how to parse such a line with mixed data types, especially where the string contains spaces between words. Some comma separated fields have more than one word as its string, with spaces separating the words. %s will read until the first space. My first field might contain 2 or 3 or more words with spaces.
- tbob

Inventor of the WORM Global
0 Kudos
Message 2 of 12
(3,137 Views)
to tbob

How about this example which parses your string like this: Resistance Test (string), Comment String (string), 5 (U16), 0 (U16), 10 (U16).
It is very rough but still does what you want.....
0 Kudos
Message 3 of 12
(3,118 Views)
There is an O'Reilly book called _Mastering Regular Expressions_ and this gets the RE concept across more than the LabVIEW help files. As most computer things are, regular expression syntax grows and builds over the course of time; there is no need to change the 'any or none' operator (*) to some other character, so learning about them in general talks to the specific LabVIEW case. LabVIEW regular expression search is rather limited in it's abilities. Compared to Perl, many single line Perl matches turn into complicated LabVIEW.

scanf is a demon unto itself. I never enjoy using it in C or LabVIEW. At least in LabVIEW it's quick to probe what is going wrong. I think the kind of gizmo you are looking for is a 'convert string to spreadsheet' that takes a cluster rather than scan spec. You declare the delimiter, and the cluster, and it returns an array of clusters loaded with the data. Of course, this type of thing needs to have error inputs and outputs, just like scanf.

Evidently, everyone is happy (or unhappy) reading text files. LabVIEW datalog files are more tightly coupled to the OS. For instance, if you declare a datalog type, file browse will restrict selection to those datalog types. This other stuff of text files being lingua franca: .TXT is an old data type, and evidently a modern language like LabVIEW sees fit to handle them with and old mindset.
0 Kudos
Message 4 of 12
(3,113 Views)
I would like to add my voice to those calling for more extensive documentation.
Even the simpler things (like how to select minimum width, or when exactly to use - or % and so on) are really hard to understand from the help file, and the few examples only help in some cases. And that's before even mentioning some more complex examples.
One nice option is using a function (like Format into String and unlike the aforementioned Spreadsheet String to Array) which has the "Edit Format String" option. This will not necessarily help all cases, but it definitely helps in some. BTW, is there any reason this feature isn't available in all the functions that use a format string? I see no reason why only some of them have it.

___________________
Try to take over the world!
0 Kudos
Message 5 of 12
(3,097 Views)
I personally would disagree. The KEY information is specified in the Help file. And if you need to understand how the things exactly work all what you need to do is just to try. I think it is very difficult to explain everything in the Help file. Understanding comes with practice. For example few days ago I was struggling with "Scan String For Tokens" nothing was clear from the available help. However after 15 minutes playing with this I understood how it works.
So instead of saying that everything is not clear just try to play with that. And you will se how simple that is.
If you have same SPECIFIC questions you can ask them in this forum. I think you will get help and some explanations.
So... practice practice practice... :)))
0 Kudos
Message 6 of 12
(3,093 Views)
I would have to disagree with your disagreement.
I assure you that both tbob and myself are perfectly capable of experimenting and finding things out, and in fact do. This is no excuse for poor documentation. There are numerous holes in the LV help, and this is just one of them. I, for one, do not wish to spend my time finding the syntax for something (one of the major points which go in LV's favor is that you don't have to bother with syntax), especially not when there is a help topic already available. There are more than enough serious things which can be found through experimentation (for instance, did you know that pressing ctrl allows you to switch the inputs on functions like + or =?).
So I'd like to restate my wish for better documentation on the format string specifiers (and for the builder to be available in all functions).

___________________
Try to take over the world!
Message 7 of 12
(3,081 Views)
If there were just two (or more) illuminating examples of using the formatting functions I would be more than happy since I am not a full time LV programmer in the strict sense.

Im quite sure there were numerous examples used to test the development of these functions so I don't quite understand why NI chose to limit useful examples to just one (1) in most cases. Sometimes the right two examples say more than a several paragraphs of explanation text.

As to the explanations, well, I leave those to the judgement of users who have to go in there now and then to use a string formatting function. Its like learning LV all over again for me.

String formatting is where LV has such strength over other languages. The fact that you can quickly construct a VI to format a string and get instant feedback about the effect you want is shared by no other language I am aware of.

My only gripe is not enough examples to show how each actually works.
We all have to build our own test Vis to see how these things work, this is not a problem. What is a problem is understanding which function to start with based on the need.

The ability of scanning several meaningful examples would be a real time saver.

btw I was hoping someone knew of a link to some help on this subject. I appreciate the feedback.
0 Kudos
Message 8 of 12
(3,053 Views)
jonni: Here is an easier way. I had already found the solution before I posted, I just wanted to mention that the Labview help was of no help. I had to find the solution by trial and error. I still can't figure out how a simple format statement of %.2f can produce both character strings and number strings. I suppose that if the string does not contain all numerical characters, it passes through as is. I would have thought that it would have been converted to NaN.
- tbob

Inventor of the WORM Global
0 Kudos
Message 9 of 12
(3,029 Views)
tst, can you explain in more detail about using ctrl to switch inputs? I tried highliting a subtraction function, pressed ctrl and nothing happened.
- tbob

Inventor of the WORM Global
0 Kudos
Message 10 of 12
(3,030 Views)