LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

I need some help manipulating String?

Hi there,

I need some help manipulating String?

I have a String with 27 elements that I save to a �.TXT� file. I�m using a �Write Characters To File� to save the characters and they are separated by an �EOL� into a 1 column. I would like to take the String and converter into 3X9 (3=columns and 9= rows), so I can open the file easily into Excel format? The file can be saved into ".TXT" file with 3x9 would be ok.

Any help or ideas would grateful,

Thanks,
0 Kudos
Message 1 of 9
(3,191 Views)
You can save your text to a csv file (comma separated variable, filename.csv), which excel can open. Just write your text to a filename.csv as such:
Text1, Text2, Text3 EOL
Text4, Text5, Text6 EOL
Notice that each element in each row is separated by a comma, and that EOL ends the row. This will produce a 3X9 text arrangement that excel can open and display as 3 columns by 9 rows.
- tbob

Inventor of the WORM Global
0 Kudos
Message 2 of 9
(3,191 Views)
Thanks for the info.

Let me try explaining this issue little differently...

I have an Array with 10X3 (10=rows, and 3=columns). The Array is 2D. (The Array contains Numbers, and Characters) Now I would like to save that Array into a file so I can retrieve my data. I have been studying some examples on File I/O but they all require String as an input. So how do I save my Array with the same dimensions or do I need to manipulate to String? If do that than everything would in a String or I can put that into a 1D array with 30 Elements?

Thanks,
0 Kudos
Message 3 of 9
(3,191 Views)
Sys Eng,

You say you have an array that contains both numbers and characters. I take it that the "numbers" are actually strings of numeric characters, right?

From your function palette, try using "String->Array to Spreadsheet String". (Set the 'format string' input to be "%s" and optionally set the delimiter to be a comma ",".) The output from this function can be passed to 'Write Characters to File.vi' and should import cleanly into Excel.

-Kevin P.
ALERT! LabVIEW's subscription-only policy came to an end (finally!). Unfortunately, pricing favors the captured and committed over new adopters -- so tread carefully.
0 Kudos
Message 4 of 9
(3,191 Views)
Hello Kevin,

Thanks for the input.

Part 1: I�m using the function �Unflatten From String� to get back to my data in Array form. So I�m taking the Array and using the functions �Reshape Array� with 10 Rows and 3 Columns. This part is fine. I can see the Array just fine.

Part 2: At same time (or same node of the �Unflatten From String� output) I am trying to save the data to a file. I�m using �Array To Spreadsheet String� to save the data to a file because I did not find any other ways to save my data in form of Array. The connections on �Array To Spreadsheet String� are; �%S� for �String Format� and �End of Line Constant�. The output of the �Array To Spreadsheet String� goes to Input of �Write Characters to File� with �File
Path�. So when I am open the file I get my results in a 1Drray with 30 elements. That data looks fine. Now, I would like to take my results which is a �String� Output from �Array To Spreadsheet String� and put them into 10X3 arrangements. So this can be easily saved as �.XLS� format or simply �.TXT�.

Thanks,
0 Kudos
Message 5 of 9
(3,191 Views)
I don't understand all of this. If you have a 10x3 numeric array, all you have to do is wire that to the 2D array input of Write to Spreadsheet File and you're basically done. The only thing you have to choose is the delimator (tab or comma) and the file name/extension.
0 Kudos
Message 6 of 9
(3,191 Views)
You've got the 2D array in Part1; just use it.
=====================================================
Fading out. " ... J. Arthur Rank on gong."
0 Kudos
Message 7 of 9
(3,191 Views)
Thanks Dennis and Donald.

The 10x3 Array is not a numeric. It is both numeric and characters. I'm attaching the file which describes what I am trying to do.

Thanks,
0 Kudos
Message 8 of 9
(3,191 Views)
An array cannot be both numeric and characters. Mixed data types are not allowed. You have a 2D string array in which the strings represent both numbers and text. There is an easy modification that can be done to Write To Spreadsheet File in order to take a 1D or 2D array of strings and write that to a file. Open the diagram of the function and look at the text box at the bottom. There is a sentence that starts "You can modify". Do the modifications and save the VI with a different name and to a new location.
0 Kudos
Message 9 of 9
(3,191 Views)