LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

String concatenation without loop

Solved!
Go to solution

Hello,

 

I have a string array containing numbers in engineering format such as below:

5.34000E-10

3.23245E-1

-8.43560E-9

 

I am trying to concatenate this string array to a header, which is a single string formed by using the concatenate strings function.  So, I would like my output to read:

 

Header line 1

Header line 2

Header Line 3

5.34000E-10

3.23245E-1

-8.43560E-9

 

However, the output currently reads:

Header line 1

Header line 2

Header Line 3

5.34000E-103.23245E-1-8.43560E-9

 

I can get the desired output using a for loop, but I do not want to do that as the concatenate strings function seems to run very slow within the loop.  Is there a way I can get the desired output without using a for loop?

 

Thanks.

0 Kudos
Message 1 of 7
(4,187 Views)

and your code is???

Labview 8.5
Meas Studio 2008
0 Kudos
Message 2 of 7
(4,179 Views)

Hi newbie,

 

what makes you think that concatenating 3 lines of text is slow?

 

Anyway two possible solutions:

check.png

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 3 of 7
(4,172 Views)

@newbie81 wrote:

I can get the desired output using a for loop, but I do not want to do that as the concatenate strings function seems to run very slow within the loop.  Is there a way I can get the desired output without using a for loop?


That a silly statement! For all practical purpose, a FOR loop is as fast as any other code doing the same stuff and it has the advantage of a cleaner diagram in the typical case of doing repetitive work. If your code is slow by any definition, obviously you are doing something wrong, however we cannot tell, since you are not showing what you are doing. Please attach your VI with some typical sample data so we can explain what is wrong an everybody learns something.

 

  • How do you measure the speed?
  • What is your definition of "slow"? (nanoseconds, microseconds, milliseconds, hours, years?)
  • How many numbers are in your array (tens, thousands, millions, billions?)

Of course there are loop-free solutions (such as Gerd's first example), but one way or another, that function has internal loops too. There is no multipurpose CPU in existence that can concatenate a large string array with only a few CPU instruction. :o:D.

0 Kudos
Message 4 of 7
(4,165 Views)

And, If you really hate concatenating inside a for loop. Just auto index your string array out of the for loop and wire the array to the concatenate strings input outside the loop.  (Yes, concatenate strings accepts arrays Smiley Wink)


"Should be" isn't "Is" -Jay
0 Kudos
Message 5 of 7
(4,159 Views)
Solution
Accepted by topic author newbie81
It is a distinct possibility that Concatenate Strings runs slowly in a For Loop. Change the statement to "I find that Build Array runs slowly in a For Loop" and we would get a serious discussion of memory thrashing. Absolutely no difference here, maybe even worse since strings are harder to predict than most data types. There may not be a magic bullet to make it fast, but there could be ways to make sure it takes no longer than necessary. I would probably just build the header as its own string array and use Build Array to join the two (concatenate inputs of course). Write to Text File will handle a string array directly when the time comes.
0 Kudos
Message 6 of 7
(4,147 Views)

The example I presented was simplistic to show the concept.  I actually have to write a citifile with on the order of 1000 rows and 2 columns.  I inherited code which does this using a for loop, and it takes approximately 13 seconds to process - waaay too slow in my opinion.  I also have a correction - the loop was not using Concatenate Strings Smiley Embarassed.  Rather, it was converting each row to a string using Format Value.

 

I have an example of my current solution attached.  I first build an array containing the header information, which are read as strings.  I then have an nx1 array of numeric data, which is how it is read from the instrument.  I convert this 1D array to an (n/2)x2 array using Disseminate 1D Array, convert this array to a string array and write to file using Write To Spreadsheet File with a comma as the delimeter.

 

This seems to work, but I have not applied it to my main VI yet....

0 Kudos
Message 7 of 7
(4,101 Views)