LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Concatenate across rows of 2D Array of strings into 1D, NO delimiter

Solved!
Go to solution

Hello fellow colleagues,

 

As shown below, I am trying to find a fast and efficient way to concatenate strings across all rows, in a 2D array, into a 1D array. The example below would normally be sufficient; however, I DO NOT want a delimiter. Notice how in this example, even though I specify a blank string for my delimiter, the function still inserts a space! I may be dealing with large data sets that require concatenation in this fashion, so I would like to iterate as LITTLE as possible in LabVIEW. I may be overlooking something obvious, if so please point it out! There may be a toolkit that includes a function that does this fast and efficiently, if so please let me know! Thanks all!

 

2D string to 1D string.JPG
l

0 Kudos
Message 1 of 17
(3,954 Views)

snip.png

 

Snap14.png

 

 

mcduff

0 Kudos
Message 2 of 17
(3,938 Views)

... or if you don't know about that "magic function" that McDuff used, you can always use For loops (the Snippet is LV 2016, but should work with almost every version):

Concat 2D Strings.png

Bob Schor

0 Kudos
Message 3 of 17
(3,934 Views)

That "magic" function is the same one you used, Smiley Tongue, I just removed one of its terminals. The function is Concatenate Strings, on the string palette. It will concatenate a string array to a single string. And there is a single For loop in my snippet.

 

mcduff

0 Kudos
Message 4 of 17
(3,929 Views)

Thanks, McDuff!  I learn something new all the time on the Forum!

 

Bob Schor

0 Kudos
Message 5 of 17
(3,925 Views)

Thanks all, but I was hoping to avoid iterating in LabVIEW. I was hoping there were some functions that did some fast "magic" under the hood, like remapping memory somehow. I know in some other programming languages you can simply take two string arrays of equal size, and concatenate them with a simple operator like "+".

 

ex. string_array_1 + string_array_2 = string_array3

Where,

string_array_1's size and shape = string_array_2's size and shape

And,

string_array_3 = 1D array of strings, where each row of string_array_1 and string_array_1 have been joined, respectively.

 

0 Kudos
Message 6 of 17
(3,922 Views)

Don't be scared of iteration, it never hurt anyone.

 

What you are asking for in your last response is different from the original question. Below is how to "Add" two 1d string arrays of the same size, however, it needs iteration, and type cast ALWAYS makes a data copy. 😞

 

Strings are always going to be memory hogs in LabVIEW, especially if they are being resized constantly.

 

mcduff

 

snip.png

0 Kudos
Message 7 of 17
(3,910 Views)

@mcduff wrote:

Don't be scared of iteration, it never hurt anyone.

 


I am definitely scared of iterating when it comes to processing large data sets, and performance is key. Of course, I will it if that's the only solution, as it may be in this case. Just thought I would reach out to the community and see if there is something I don't know 😃

 


@mcduff

What you are asking for in your last response is different from the original question. Below is how to "Add" two 1d string arrays of the same size, however, it needs iteration, and type cast ALWAYS makes a data copy. 😞

 


Actually, the intent is still very much the same. Please see image below. Also, why would you want to cast that data? If your iterating anyways, why not just concatenate? see comparisons below. Thanks!

 

EDIT, made a label mistake, just updated photo sorry. Also, the type casting method seems to interleave the text, not what I was intending. But thanks!

 2D string to 1D string - comparison.JPG

0 Kudos
Message 8 of 17
(3,902 Views)

@airalex1919

 Actually, the intent is still very much the same. Please see image below. Also, why would you want to cast that data? If your iterating anyways, why not just concatenate? see comparisons below. Thanks!


I was trying not to use loops with those methods, I was starting to use reshape arrays, string to bytes, etc, and then had to do work that pays. Pass it along to the Rube-Goldberg thread. Smiley Happy

 

mcduff

0 Kudos
Message 9 of 17
(3,897 Views)

PS Your timing comparison is not good, run each method without any others. Yes LabVIEW can do tasks in parallel, but you cannot predict the order.

 

mcduff

Message 10 of 17
(3,895 Views)