infinitenothing Posted January 28, 2021 Report Share Posted January 28, 2021 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" ? Quote Link to comment
JKSH Posted January 28, 2021 Report Share Posted January 28, 2021 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? Quote Link to comment
infinitenothing Posted February 3, 2021 Author Report Share Posted February 3, 2021 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. Quote Link to comment
mcduff Posted February 3, 2021 Report Share Posted February 3, 2021 Maybe this thread can help, if you haven't seen it before mcduff Quote Link to comment
infinitenothing Posted February 7, 2021 Author Report Share Posted February 7, 2021 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. Quote Link to comment
LogMAN Posted February 7, 2021 Report Share Posted February 7, 2021 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). Quote Link to comment
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.