10-11-2018 02:36 PM - edited 10-11-2018 02:36 PM
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!
l
Solved! Go to Solution.
10-11-2018 03:27 PM
mcduff
10-11-2018 03:38 PM
... 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):
Bob Schor
10-11-2018 03:43 PM
That "magic" function is the same one you used, , 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
10-11-2018 03:50 PM
Thanks, McDuff! I learn something new all the time on the Forum!
Bob Schor
10-11-2018 03:55 PM
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.
10-11-2018 04:31 PM
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
10-11-2018 04:53 PM - edited 10-11-2018 05:02 PM
@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 😃
@mcduffWhat 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!
10-11-2018 05:01 PM
@airalex1919Actually, 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.
mcduff
10-11-2018 05:03 PM
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