05-19-2014 09:06 AM
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
Solved! Go to Solution.
05-19-2014 09:11 AM - edited 05-19-2014 09:11 AM
in 1000 words equivalent
05-19-2014 09:13 AM
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.
05-19-2014 09:43 AM
Good Idea Paul!
05-19-2014 10:49 AM - edited 05-19-2014 10:50 AM
@JÞB wrote:
Good Idea Paul!
Very good idea. Except, I would just use Replace Substring instread of converting to a byte array and back again.
05-19-2014 01:16 PM - edited 05-19-2014 01:18 PM
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.
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.