LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How can you determine if a character in a string is numeric or alphabetic?

Hello all,

I've been trying this one for awhile now, and can't find any way to do it.

I am reading a character string out of a text file. The string is a number. I need to convert that number to it's decimal equivalent -- this is not a problem, I can do this easily.

The problem comes in when I'm reading the string from the text file. I want to be able to be sure that they didn't have a typo and insert an alphabetic character into the number. For example, typing 50o instead of 500. If I convert this example, I will read 50. I want it to flag an error instead, but I cannot figure out how to read the string and determine if there are alphabetic and numeric characters in the string I'm
reading.

Any help would be greatly appreciated.

Dave Neumann
d.neumann@astronautics.com
0 Kudos
Message 1 of 5
(5,850 Views)
Thanks everyone, but I figured it out already.

Doh! It was rather simple!

Thanks again,

Dave Neumann
0 Kudos
Message 2 of 5
(5,850 Views)
Use the "decimal digit?" function to check the string elements, individual elements can be retrieved with the "string subset" function.
0 Kudos
Message 3 of 5
(5,850 Views)
Hi Dave,

Convert the string to an array of ASCII codes by using the string to byte array function and test the array for values outside of the range of 48 to 57 (numerals 0 thru 9). Decimal point is ASCII 46.

Also, if you are using the LV string to number conversions for converting from strings to numbers a value returned for the 'offset past number' value that is less than the length of the string is indicative of an illegal text character for that type of conversion in the string.



Good Luck!
Message 4 of 5
(5,850 Views)
You can also use the "Scan from String" function. If the "remaining string" output is not a null string, or the error output is reporting an error, something went wrong with the conversion.

Mike...

Certified Professional Instructor
Certified LabVIEW Architect
LabVIEW Champion

"... after all, He's not a tame lion..."

For help with grief and grieving.
0 Kudos
Message 5 of 5
(5,850 Views)