09-02-2015 12:00 PM
Hi,
I need help to format my 2D array into a string.
I have a DBL 2D array like this:
and I want it in a string format like this "0 0.12, 1 0.34, 2 0.11"
Row 0 Col 0 <space> Row 0 Col 1 <comma> Row 1 Col 0 <space> Row 1 Col 1 <comma> Row 2 Col 0 <space> Row 2 Col 1 ... and so on
Is this doable with "Array to spreadsheet string" function or do I need to use a for loop to format it in this way?
Thanks,
Ritesh
Solved! Go to Solution.
09-02-2015 12:02 PM
Array to spreadsheet string cause use space as a delimiter like you want between each column, but will always use End of Line character for the end of each row.
You could use a simple nested For loop setup to do what you want.
Cheers
--------, Unofficial Forum Rules and Guidelines ,--------
'--- >The shortest distance between two nodes is a straight wire> ---'
09-02-2015 12:21 PM
Here what I would do
09-02-2015 12:33 PM
Sorry for the little bug, here is the corrected version. Notice that inner for loop has a space after %s in "false" case.
09-02-2015 12:44 PM - edited 09-02-2015 12:48 PM
Well, I made a really simple version. Ignore my nested For loop idea above.
Here's what you want. This just bypasses the 2D aspect and allows you to customize everything as 1D arrays.
(Adjust the %#_2f format to match the precision you want. The 2 I used just meeans it will max you out at two decimal places)
Freelion, you can clean what you did up a lot by just using the Trim Whitespace node.
Cheers
--------, Unofficial Forum Rules and Guidelines ,--------
'--- >The shortest distance between two nodes is a straight wire> ---'
09-02-2015 12:48 PM
Thanks for your suggestions! I have implemented a "for loop" solution which has less code than the one suggested on this thread.
Let me know if you guys think there is a simpler solution to this problem. I was thinking of using "Array To Spreadsheet String" vi but couldn't get what I want.
09-02-2015 12:55 PM
Did you se my latest reply? I think that's simpler than what you did. It uses Array to Spreadsheet String, but only for 1D conversion.
Cheers
--------, Unofficial Forum Rules and Guidelines ,--------
'--- >The shortest distance between two nodes is a straight wire> ---'
09-02-2015 01:07 PM - edited 09-02-2015 01:10 PM
09-02-2015 01:14 PM
Hi James, it was something I made in 5 min. which gives him what he wants. Does your code have a space after comma? If so, it is not exactly what he asked for.
09-02-2015 01:16 PM - edited 09-02-2015 01:20 PM
@ben64 wrote:
Here are 2 ways to do it without loop.
Ben64
EDIT: just realized you want a comma to separate rows, replace the tab by a comma in solution 1. (solution 2 will not work in this case)
What's up with that funky pattern replace VI? I haven't seen that before. This would be my version:
Freelion, it does have a space after the comma because that's what his example output had from OP's original post. The space can be removed, or any delimiter can be put in its place.
Cheers
--------, Unofficial Forum Rules and Guidelines ,--------
'--- >The shortest distance between two nodes is a straight wire> ---'