LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How can I know a string only includes number?

Dear All,
         How can I know a string only includes number(0,1,...9). Except to judge one character by one character.
         And How to judge it is an integer not a decimal fraction.
         Is there a vi to do it?
         Thanks for any suggestion.
 
 
Hugo
0 Kudos
Message 1 of 13
(3,963 Views)
Hi Hugo,

well, the difference between integer and fractional numbers is the decimal separator sign (either "." or ",", depending on location/OS setting). As you are testing for "only includes numbers" this is already given in the test...

To test full strings for numbers you can use this:
The string is converted to U8 array and tested for "In Range" of all chars in the string...


Message Edited by GerdW on 06-19-2008 12:45 PM
Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 2 of 13
(3,961 Views)
GerdW,
Thank you for your help!
Thanks.
I will try under your suggestion.
 
 
Hugo
0 Kudos
Message 3 of 13
(3,944 Views)
Gerd implemented exactly how I would have done it. 
 
Message 4 of 13
(3,941 Views)
One question since you asked about decimal vs fraction.  Do you want fractional values to be considered numbers?  Many people forget that '.' (or ',' for some countries) is a character as well when they look to see if a string is a number.  If you want fractionals to be considered a number, you will have to account for the separator.
Jon D
Certified LabVIEW Developer.
Message 5 of 13
(3,920 Views)

The way I do it is to convert everything to ASCII and scan for the range of numbers as shown in the example, and also look for the period and comma.  That covers all angles. 

RayR

Message 6 of 13
(3,914 Views)

As shown in this example:



Message Edited by JoeLabView on 06-19-2008 09:24 AM
Message 7 of 13
(3,902 Views)
I Like using REs.  the RE [0-9]+([.,][0-9]+)?[0-9]* Matches one or more number digits followed by an optional period or comma and at least one digit followed by zero or more optional digits at the end.  This will validate pull out the first integer or float.  Looking at if a match was made and if there were any characters before or after the match will let you know if you found an integer or float as well if it was an exclusive string match.
 
Paul
Paul Falkenstein
Coleman Technologies Inc.
CLA, CPI, AIA-Vision
Labview 4.0- 2013, RT, Vision, FPGA
Message 8 of 13
(3,898 Views)

Good suggestion Paul,

Another thing to consider is Engineering Notation:  1.23E+12

😉

Message 9 of 13
(3,882 Views)
... and don't forget negative numbers or numbers with an optional leading "+".
 
How about si notation? 😄
Message 10 of 13
(3,866 Views)