12-21-2012 02:50 PM
Hello all,
i would lik to round up a text string so that it fits in our pre decided header size. how can i do it? any one has any logic/
For Ex: Length of string deciced: 6
String Entered by user: LABVIEWrocks
Output string as result of rounding, LABVIEW so, rocks is removed out...
thanks,
Solved! Go to Solution.
12-21-2012 02:54 PM
@LV_Enthu wrote:
Hello all,
i would lik to round up a text string so that it fits in our pre decided header size. how can i do it? any one has any logic/
For Ex: Length of string deciced: 6
String Entered by user: LABVIEWrocks
Output string as result of rounding, LABVIEW so, rocks is removed out...
thanks,
Same as for any programming language, really. I think the node you're looking for is "String Subset." 🙂
12-21-2012 02:54 PM - edited 12-21-2012 02:55 PM
Spend some time looking around the string palette and you'll find that the function you need is there, pretty clearly labeled: String Subset.
EDIT: By the way, you might want to check your math: LabVIEW is 7 characters, not 6.
12-21-2012 02:59 PM
I would not call that a roundup function. It sounds like that all that you need is the basic String Subset function.
p.s. Your arithmetic is wrong. If you specify a 6 with the string "LABVIEWrocks", the output string would be "LABVIE", not "LABVIEW".
12-21-2012 05:13 PM
Here is a more generic method that will let you know how many characters you can fit into an indicator. It calculates it based on the size of the indicator and the font settings. Then as suggested use string subset to truncate the string.
12-21-2012 05:52 PM
ALL,
THANKS FOR THE INPUTS, typo on the math..
how would i get the other way, example, if user enters LAB, i would like to append '000' at the end of string to make the size of string always equal to 6.
12-21-2012 08:22 PM
I hope we're not doing your homework for you here. Have you looked at the string palette at all? The functions you need are all there.
Here's one approach: check that the input string doesn't exceed the desired length. Create a string of all 0's of the correct length. Use "Replace Substring" to insert the input string into the string of 0's. Creating that string of all 0's will be slightly more complicated than it should be, but a combination of string to byte array, index array, initialize array, and byte array to string will do it.
12-22-2012 09:28 AM
Hi hope this helps you