Lucki Posted March 25, 2015 Report Share Posted March 25, 2015 (edited) Why not use simple the "in string search.vi" for recognition a number- string? convert numeric string.vi Edited March 25, 2015 by Lucki Quote Link to comment
hooovahh Posted March 26, 2015 Report Share Posted March 26, 2015 Why not use simple the "in string search.vi" for recognition a number- string? I hate being the one to ask...but could someone post this in 2013 or older? I'm in a PC transition and that's the only version I have installed at the moment. Quote Link to comment
ShaunR Posted March 26, 2015 Report Share Posted March 26, 2015 I hate being the one to ask...but could someone post this in 2013 or older? I'm in a PC transition and that's the only version I have installed at the moment. convert numeric string2009.vi 1 Quote Link to comment
hooovahh Posted March 26, 2015 Report Share Posted March 26, 2015 Lucki you win on simplicity for sure. But just to save a little bit of face I did a speed test and my method appears to be about 10 times faster on my I7 machine in LabVIEW 2013 SP1. Of course our two methods don't always return the same result. Yours considers NaN a number and depending on the application I could see wanting this feature or not, so I added it to mine. Also your method accepts scientific notation like "4e6" where mine doesn't, and yours accepts imaginary numbers like "1 + 2i" where mine doesn't. I never mentioned my application for this but I using this where a user can enter into a table some number. The table is of course a string but it needs to be evaluated for being a number otherwise indicate it is formatted incorrectly. In this case the user shouldn't ever think of entering NaN but if they do I'd consider that an invalid entry. Same with "4e6", generally users will think in floating point and would type the extra zeros. And users shouldn't enter imaginary numbers. Of course all these things are up to the developer to decide what types of input should be considered valid. Quote Link to comment
eberaud Posted March 26, 2015 Report Share Posted March 26, 2015 I think you should only accept the negative sign (-) to be at the beginning of the string. Right now it will accept "5-5" but that's not really a number... Quote Link to comment
hooovahh Posted March 27, 2015 Report Share Posted March 27, 2015 I think you should only accept the negative sign (-) to be at the beginning of the string. Right now it will accept "5-5" but that's not really a number... Very good point, that isn't hard to add, just look evaluate the negative symbol only on the first iteration of the for loop. Quote Link to comment
Stormshadow Posted August 11, 2017 Report Share Posted August 11, 2017 (edited) I ended up with issues after using this one for over a year because it ignores spaces before the number: http://rosettacode.org/mw/images/f/fb/LabVIEW_Determine_if_a_string_is_numeric.png This is my version that allows NaN, Inf, -Inf to work and spaces are considered as a string. .1 doesn't work, but a condition can be easily added. Sorry for digging up an old thread, but this is the first link on Google and another thread would just get lost. This gives another alternative to the suggestions offered in this thread. Edited August 11, 2017 by Stormshadow 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.