Jump to content

Is there an "in place" number to string function?

Recommended Posts

Lets say you wanted to be totally fixed in memory and you wanted to print something like "January 13th". You could figure out the longest string that could possibly exist and copy your number (13) into there and pad the rest with spaces or something but most of the functions I've seen in LV like number to string and array to spreadsheet string all seem to output a variable sized string. Are there any functions that take in a number and an input string and writes the number "in place" ?

Link to post

Not that I know of, but you could use a pre-allocated array of bytes (U8) and replace individual characters with their ordinal values (see https://www.asciitable.com/ -- '1' == 49, '3' == 51)

Byte Array to String is a type-cast that doesn't allocate new memory. Of course, if you branch the wire (or keep a copy of the string) and then modify the original byte array, then you'd obviously still need to allocate new memory.

May I ask why you need to micro-manage memory usage to this level?

Link to post

That works well for numbers <9. If you have a bigger integer you'd have to do something like successive modulo divide by 10s to break up the number and update each byte individually. I guess I was hoping someone else did the heavy lifting.

As for why, I have an application where I'm generating many strings and I'd like to be "in place" all the way down for performance or determinism reasons. I can also imagine situations where you might want to do something like this on an FPGA where memory is fixed.

Link to post

That's potentially useful but I can always do my own fixed strings by using things like "replace string subset" or by operating with an Array of U8s. It's more the output of number to string conversion that's not fixed that's my issue at the moment.

Link to post
6 hours ago, infinitenothing said:

It's more the output of number to string conversion that's not fixed that's my issue at the moment.

The number to string functions all have a width parameter: Number To Decimal String Function - LabVIEW 2018 Help - National Instruments (ni.com)

As long as you can guarantee that the number of digits does not exceed the specified width, it will always produce a string with fixed length (padded with spaces).

Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...

Important Information

By using this site, you agree to our Terms of Use.