01-10-2011 12:37 PM
What little forethought I put into these nuggets would have me jumping around to various places in vi.lib. But, since I intend these to be VIs I find useful in vi.lib, when I reach for one particular VI several times in the past few days it seems worthy of getting bumped up in the rotation. Back to the same directory as last week: vi.lib/AdvancedString, this time we find Join Strings.vi. Simple enough, you pass in an array of strings and a delimiter and get back a delimited string.
Wait a second? Can't you do this with Spreadsheet Array to String?
Yes you can. But as you soon discover, that function likes to tack on the EOL string, which has lovely properties. Not only is it platform dependent, its length is platform dependent. You can't just obliterate the last character, if you care about portability, you have to check the length of the EOL string and act accordingly. With Join Strings, no EOL, no fuss.
Now if only the terminal lined up with the icon image....
01-10-2011 02:05 PM
Cool, I didn't know that VI was there. Interestingly, when I benchmark it, this VI is about twice as fast as Array to Spreadsheet String. And it has the benefit of not adding the EOL at the end. Seems like, when dealing with a 1D array of strings, this VI is definitely preferred over the built-in function.
01-10-2011 02:41 PM
Thanks Darin.
No need to call it a "weakly" nugget though- its pretty tough.
01-10-2011 03:00 PM
@Darren wrote:
Cool, I didn't know that VI was there. Interestingly, when I benchmark it, this VI is about twice as fast as Array to Spreadsheet String. And it has the benefit of not adding the EOL at the end. Seems like, when dealing with a 1D array of strings, this VI is definitely preferred over the built-in function.
Elegance and efficiency, that's often a winning hand.
I know that there is at least one other NI person who wasn't aware. If you look next door in the AdvancedString folder at the Relative Path to Platform Indpendent String.vi you will find this:
@Jeff - Thanks. If I stick with the title I am free from copyright infringement, and I am not compelled to do this on a particular timescale. I do think it is pretty good info, for every one that makes the cut, there are plenty of these guys lurking around.
Ah, memory lane....
01-10-2011 03:32 PM
Do you know how many times I've coded something like this?
And This was here all along
Fun little palatte
01-10-2011 08:51 PM
Thanks for the info Darin, i never knew that there was a folder full of goodies. Just for my curiosity, why arent these vi's on the palletes? I suppose i will have to learn how to add them myself, sure if i look there is an old nugget on that.
Rgs,
Lucither.
01-10-2011 09:32 PM - edited 01-10-2011 09:32 PM
@Darren wrote:
Interestingly, when I benchmark it, this VI is about twice as fast as Array to Spreadsheet String.
... depending on the number of elements in the input array.
And for the speed freaks out there, if you roll your own you can beat the Join String by about 4x for small input arrays. You break even around 1000 elements, and Join Strings becomes faster for large input arrays.
But +1 for the vi.lib find, I prefer to use someone else's managed code. 😉
01-10-2011 09:38 PM - edited 01-10-2011 09:44 PM
@Lucither wrote:
Thanks for the info Darin, i never knew that there was a folder full of goodies. Just for my curiosity, why arent these vi's on the palletes? I suppose i will have to learn how to add them myself, sure if i look there is an old nugget on that.
It is an interesting hodgepodge in there. A lot of useful stuff, a lot of useless stuff, and a lot of stuff that I have no clue about because of password protection. Many VIs in there are, in fact, in the palettes. Most of the VIs I like are helpers, or subVIs used in the VIs which appear on the palettes.
I don't fuss with palettes much, two things I do are (1) have a shortcut to vi.lib on my desktop, and I can find my favorites from there. (2) I have a catalog VI where I drag all of my potentially useful VIs to the BD and arrange them by group. It helps me find any potential gotchas when I upgrade versions and is useful when I forget where to find something. I will post that someday, but right now it would be the mother of all spoilers....
Edit: Homework exercise for Jack: Estimate the time it takes to roll your own version. Divide that by the microseconds shaved (for small arrays) and tell me how many operations does it take to break even? You hit the nail on the head, one of the things I like best about finding these VIs is that maintenance is their problem not mine. (Even better, some VIs I will show are by necessity quite ugly, this way I can blame NI).
01-11-2011 01:39 AM
I didn't know about this either, but I do use the OpenG 1D Array to String VI which does the same thing.
01-11-2011 03:48 AM
A nice-little micro-nugget hidden in here:
(2) I have a catalog VI where I drag all of my potentially useful VIs to the BD and arrange them by group. It helps me find any potential gotchas when I upgrade versions and is useful when I forget where to find something.
Catalog.vi=Tree.vi=Fakeroot.vi
Felix