Posted by Abe Gillespie on January 24, 2001 at 16:49:13:
In Reply to: Re: isNum() or isInt() function? posted by Brian Kelly on January 24, 2001 at 14:07:19:
sure, it'll compare the string. but say you have two strings: s1 = "11" and s2 = "9" and you try s1 > s2. this returns false becuase text is compared differently than numbers. so we need to make sure that we have integer variables and string variables used at the appropriate times.
abe
: Hmm, which case would that be? I thought that anything in the string (chars, ints, floats, etc.) would be converted to some arbitrary value that could always be compared no matter what the data in the string was. i.e. In an old project we had to compare course names / numbers: MATH1205 & MATH 1206. By storing them as strings it was easy to compare a mixture of letters and numbers and sort them in the correct ascending order.
: I thought that was a great feature of the string class. Are there more caveats I'm missing?
: Thanks,
: Brian
: : And, if you compare the numbers as strings you'll get the wrong orderings in some cases...
: : : Why? Comparison operators have been overloaded for the string class. You can if you choose to simply read in your numbers as strings and compare them that way. It'd keep things much simpler.
: : : -Jay
: : : : is there a function that takes a string or char array and returns true or false whether it is a number or an integer? or something along this thinking
: : : : thanks
: : : : abe gillespie