LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Null padded string

Solved!
Go to solution

I need to create a string padded if with 0x00 if length is not met.

 

sample

 

lenght = 30

input = 123456

 

should look like this in hex

 

0x 3132 3334 3536 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000  

 

or in "/" display

123456\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00

 

tried "format into string"  It either won't work for padding with 0x00 or I'm not formatting it correctly

 

0 Kudos
Message 1 of 6
(3,385 Views)

in 1000 words equivalent

!1.png


"Should be" isn't "Is" -Jay
Message 2 of 6
(3,382 Views)

Why not start with a null padded string (init a u8 array to size 30 and convert to string) then replace the front of the string with replace string subset.

Paul Falkenstein
Coleman Technologies Inc.
CLA, CPI, AIA-Vision
Labview 4.0- 2013, RT, Vision, FPGA
0 Kudos
Message 3 of 6
(3,380 Views)

Good Idea Paul!Smiley Very Happy


"Should be" isn't "Is" -Jay
0 Kudos
Message 4 of 6
(3,361 Views)
Solution
Accepted by topic author RRRRSSSS

@JÞB wrote:

Good Idea Paul!Smiley Very Happy


Very good idea.  Except, I would just use Replace Substring instread of converting to a byte array and back again.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 5 of 6
(3,344 Views)

One more suggestion (which I think is simpler than the above proposals): convert to a byte array, reshape the array, convert back to string. String to Byte Array, and vice versa, are free operations - they do not allocate memory buffers or make data copies.

PadString.png

EDIT: before someone points this out, yes, this only pads with nulls. If you need to pad with some other character, use on of the other suggestions.

Message 6 of 6
(3,308 Views)