LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

convert an array of strings into a single string

Hi
 
I am having trouble trying to figure out how to convert an array of strings into a single string.
 
I am taking serial data via serial read in a loop to improve data transfer.  This means I am taking the data in chunks and these chunks are being dumped into an array.  However I want to combine all elements in the array into a single string (should be easy but I can't seem to make it work).
 
In addition to this I would also like to then split the string by the comma separator so if any advice could be given on this it would be much appreciated.
 
Many Thanks
 
Ashley.
0 Kudos
Message 1 of 10
(18,369 Views)

Hi Ashley,

You can do it all with the function 'Array to Spreadsheet String'

 

0 Kudos
Message 2 of 10
(18,363 Views)
Thanks KC 
 
For some reason I had assumed that the array to spreadsheet string could only deal with an array of numeriuc inputs.
 
Ashley
0 Kudos
Message 3 of 10
(18,360 Views)
Well the input shows a DBL array but you can attach a string array. Smiley Surprised  Just something you have to know.
0 Kudos
Message 4 of 10
(18,353 Views)
Hi again KC
 
Sorry to be a pain.  Using the array to spreadsheet string worked fine, however, when I am having trouble rearraging the string back into an array in which each element is a a sub-string contained between coma separators.
 
i.e. I would like the string xxxx, xxxx , xxxx, xxxx etc.... to be rearranged into an array:
 
1    xxxx
2    xxxx
3    xxxx
4    xxxx
      etc.....
 
The reason is the each coma separated sub-string is a hexadecimal word.  If each word is arranged in an array like this I will be able to convert each to a decimal number in a for loop and hence pull out the data I need.
 
incidentally many thanks for your help on the problem I was having reading serial data.  That is cured now I attach the modified code for your reference.
 
Many thanks
 
Ashley.
0 Kudos
Message 5 of 10
(18,339 Views)
You don't even have to use a For loop : the string convert vis run on arrays...
See the attached vi.
 
Chilly Charly    (aka CC)
0 Kudos
Message 6 of 10
(18,332 Views)
Hi Ashley,
 
Everything clear, I think, with the answer of CC ?
0 Kudos
Message 7 of 10
(18,318 Views)

Yes thank you, all was good with Chilly Charley's message.

Just one thing.  I seem to have a recurring empty sub-string in the string I am reading.  When converting from hexadecimal text to decimal numbers this empty string is being returned as 0.  Thus in my numerical array output I have intermittent zeros (which aren't real data). Is there any quick fix to remove the empty string character from the read string so I don't get these zeros

Many thanks for your patience

Ashley.

0 Kudos
Message 8 of 10
(18,314 Views)
Well, you don't even need to create the intermediary string array, right? This does exactly the same as CCs attachment:
 
 

Back to your serial code:
 
Why don't you built the array at the loop boundary? Same result.
 
 
 
You could even built the string directly as shown here.
 

Message Edited by altenbach on 12-20-2005 09:39 AM

Download All
Message 9 of 10
(18,314 Views)
You could test the string lenght using the String Length function.  Put your code to convert the string to a number inside a case structure.  Wire String Length to the Greater Than Zero function (>0).  Wire output of >0 to case selector.  Convert string to number only if string length is greater than zero (True case).  Do nothing in False case except passing the array untouched.
- tbob

Inventor of the WORM Global
0 Kudos
Message 10 of 10
(18,297 Views)