annulla
Visualizzazione dei risultati per 
Cerca invece 
Intendevi dire: 

Null padded string

Risolto!
Vai alla soluzione

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
Messaggio 1 di 6
4.396Visualizzazioni

in 1000 words equivalent

!1.png


"Should be" isn't "Is" -Jay
Messaggio 2 di 6
4.393Visualizzazioni

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
Messaggio 3 di 6
4.391Visualizzazioni

Good Idea Paul!Smiley Molto-felice


"Should be" isn't "Is" -Jay
0 Kudos
Messaggio 4 di 6
4.372Visualizzazioni
Soluzione
Accettato da autore argomento RRRRSSSS

@JÞB wrote:

Good Idea Paul!Smiley Molto-felice


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



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
Messaggio 5 di 6
4.355Visualizzazioni

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.

Messaggio 6 di 6
4.319Visualizzazioni