LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Getting a weird [extra?] space when using Format Into String and EOL

I am trying to bring in a spreadsheet file (txt format) and export it in a specifically formatted text file.

This is what I bring in(tab del)
0.0000    5.0000    2.5000    556.5800    2045.1900    1300.8800    8.0000           
0.3670    1.4210    3.2660    6.4220    32.6170    42.4090    54.0790    74.7330       
5.6300    3.0700    2.0500    1.0200    2.0500    3.5800    1.0200    0.5100      

I use Read From Spreadsheet and use the resulting array as shown in the picture.  My program reads each line(in array format), takes each elt of the subarray,formats it as a string, and writes it to file.


                         
The reformatted file will have all numbers right justified, and padded on the left with spaces.  The numbers *should* have a field width of 10, with padding spaces on the left side, with no spaces to the right.

  0.0000    5.0000    2.5000  556.5800 2045.1900 1300.8800    8.0000
  0.3670    1.4210    3.2660    6.4220   32.6170   42.4090   54.0790   74.7330
  5.6300    3.0700    2.0500    1.0200    2.0500    3.5800    1.0200    0.5100


My problem lies in the fact that I have to specify a field width of 9 instead of 10 b/c I am getting an extra space on the RIGHT of the number. This is bad b/c when I add the EOL constant at the end of the line, it has a space to the left of it.



This will not do as this text file is to be imported into another program that will convert the data into a corresponding xml file.

Can someone tell me where this space is coming from? I'm sure it is something that is pretty obvious, but I am still learning.

Thanks so much.

0 Kudos
Message 1 of 4
(3,256 Views)
Simple, it's from your format string.
 
%9.4f %9.4f %9.4f %9.4f %9.4f %s
 
should be
 
%10.4f%10.4f%10.4f%10.4f%10.4f%s
 
You're adding an extra space in between the elements of this string.
Message 2 of 4
(3,248 Views)

Hi Candice,

It looks as though you have spaces in the format string after each "f" and before the following "%". So you are telling the format into string to add a space after each number. If you don't want the spaces leave them out of the format string. So your format string should read

"%10.4f%10.4f%10.4f........%10.4f%s"

(Note: NO spaces)

Rod.

 

Message 3 of 4
(3,244 Views)
That is SO funny. I guess I figured if you wanted a space there, you would have to use a %c and code it in there.  Shows just how much I know! 🙂

Thanks for pointing that out to me.

Ciao!
0 Kudos
Message 4 of 4
(3,231 Views)