LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Padding String with 0's on the left - A better, Simple method?????

Hello,

I'm looking to have the front part of an integer number padded with 0's.

I've attached a VI that works but it seems to be a bit more complicated than it needs to be so looking for a leaner solution if possible.

I've tried using the syntax formatting but wasn't able to get it to work.

The total width (with padding) should be 3 spaces.

Here are some examples of what I'm looking to do:

"1" should have an output string of "001"

"2" gives "002",   "99"  gives "099",  "100" gives "100",  "999" gives "999"

If anyone has any ideas I would appreciate the help.

best
SS
0 Kudos
Message 1 of 19
(17,587 Views)




Hope this helps



Message Edited by TiTou on 07-03-2008 09:38 AM

We have two ears and one mouth so that we can listen twice as much as we speak.

Epictetus

Antoine Chalons

Message 2 of 19
(17,585 Views)
Smiley Very Happy

Smiley Very Happy

hahahahahaha....wow I feel like an idiot!

thanks for the help!!!!!!!

best
SS
0 Kudos
Message 3 of 19
(17,576 Views)
No you don't :), we all miss obvious thing sometimes and it's being wise to go and ask someone else !

We have two ears and one mouth so that we can listen twice as much as we speak.

Epictetus

Antoine Chalons

0 Kudos
Message 4 of 19
(17,573 Views)
Titou, I am tryng to print a 2D array (of strings) to a label.  Everything is ALMOST perfect, except that there is a tab issue (I beieve) that is throwing the top row (header information) off by one column (see screen capture).  I'm trying to incorporate a  Format Into String node to pad the values as necessary.  Not having any luck...can you point me in the right direction...PLEASE?
0 Kudos
Message 5 of 19
(17,385 Views)
DanNatCorning, remove the Format into string, it is operating on the entire spreadsheet string which already has more than 30 characters.  Move the '%30s' into the format string of the ArraytoSpreadsheetString vi to pad the individual entries.
Message 6 of 19
(17,379 Views)

Darin, I feel like an idiot, but I certainly appreciate the help.  You made my weekend

 

0 Kudos
Message 7 of 19
(17,363 Views)
Darin, I am still struggling with the correct format string.  I've tried 10 or 15, but I can't get the right combination to truncate the values to 3 decimal places, but space the column correctly too...can you help me out?
0 Kudos
Message 8 of 19
(17,342 Views)

Look, you already have a 2D array of strings, and unlike numerics, strings have no special meaning for the decimal point.

 

You need to solve the problem upstream, when the relevant data fields are still numeric. Alternatively, you need to do some fancy parsing of the strings.

 

Can you attach the actual VI instead of pictures?

0 Kudos
Message 9 of 19
(17,331 Views)
Also, please upload screenshots directly as PNG, JPG, or GIF files (NOT BMP). Don't embed them inside of Microsoft Word.
0 Kudos
Message 10 of 19
(17,309 Views)