LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

HOW TO ROUND UP TEXT STRING?

Solved!
Go to solution

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,

 

Now on LabVIEW 10.0 on Win7
0 Kudos
Message 1 of 8
(3,024 Views)

@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."  🙂

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 2 of 8
(3,018 Views)

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.

0 Kudos
Message 3 of 8
(3,017 Views)

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".

0 Kudos
Message 4 of 8
(3,014 Views)

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.

 

Size Text To Indicator.png



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
0 Kudos
Message 5 of 8
(2,994 Views)

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.

Now on LabVIEW 10.0 on Win7
0 Kudos
Message 6 of 8
(2,987 Views)

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.

0 Kudos
Message 7 of 8
(2,973 Views)
Solution
Accepted by topic author LV_Enthu

Hi hope this helps you

 

String.png

0 Kudos
Message 8 of 8
(2,958 Views)