LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Darin's Weakly Nugget - 1/10/11

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.

 

Join Strings.png

 

Now if only the terminal lined up with the icon image....

Message 1 of 14
(5,542 Views)

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.

Message 2 of 14
(5,514 Views)

Thanks Darin.

 

No need to call it a "weakly" nugget though- its pretty tough.  Smiley Wink


"Should be" isn't "Is" -Jay
Message 3 of 14
(5,489 Views)

 


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

 

Join Strings Hard.png

 

@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.   Smiley Very Happy  I do think it is pretty good info, for every one that makes the cut, there are plenty of these guys lurking around.

 

OldVI.png

 

Ah, memory lane....

 

 

 

 

Message 4 of 14
(5,481 Views)

Do you know how many times I've coded something like this?

Split String.png

 

And This was here all along

 

Split String2.png

 

Fun little palatte

 

 

 

 


"Should be" isn't "Is" -Jay
Message 5 of 14
(5,459 Views)

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.

------------------------------------------------------------------------------------------------------
"Everything should be made as simple as possible but no simpler"
0 Kudos
Message 6 of 14
(5,410 Views)

 


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

 

ArrayToSpreadsheetStringResults.png

 

ArrayToSpreadsheetStringBenchmark.png

 

Message 7 of 14
(5,393 Views)

 


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

 

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

Message 8 of 14
(5,389 Views)

I didn't know about this either, but I do use the OpenG 1D Array to String VI which does the same thing.


___________________
Try to take over the world!
0 Kudos
Message 9 of 14
(5,359 Views)

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

0 Kudos
Message 10 of 14
(5,335 Views)