LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

String to Number Conversion Problem

jc,

 

Here is a little VI which I put together for a situation where I needed to transfer some string data but had only an array of DBL in the transfer path.  It even encodes and decodes error clusters to the array of DBL.  You can transfer a string of any size, at the rate of one DBL per character.  It is not efficient use of memory, but it is fairly simple.  Perhaps this will give you some ideas. 

 

Lynn 

Message 11 of 14
(735 Views)

Padding! Of course. The very first thing I tried was using the Typecast function, but I assumed that the padding would be handled internally so my initial tests gave a result of zero...literally.

 

I knew my code was pretty abstract, but I was beginning to think it was necessary to get the desired result. I would still be interested in the possibility of compression, but ultimately I might be required to span the input STRING over several DBLs in my parameter cluster array.

 

For the sake of compression let's make two different case assumptions:

1) using the basic ASCII character set (7-bit)

2) using the Extended ASCII character set (8-bit)

 

And how would padding be handled. I was thinking it would just be represented by a certain character, but what if you are using all 256 characters for the 8-bits?

 

~jc

 

 

0 Kudos
Message 12 of 14
(721 Views)

If the string is variable length (max 8 characters) and there is a character that is not allowed (e.g. \FF or \00), you can pad the string to 8 bytes with it and later trim it off again. Here's one way to do this.

 

Message Edited by altenbach on 04-22-2009 11:29 AM
Message 13 of 14
(717 Views)

JRC_Tinker wrote:

And how would padding be handled. I was thinking it would just be represented by a certain character, but what if you are using all 256 characters for the 8-bits?


As mentioned, if you only use 7 bytes, you can use the 8th byte to encode the actual lenght. if you use all 8 bytes, you need to carry the information elsewhere, there is no room!

Message 14 of 14
(710 Views)