st.SetValue(‘’)
ret = st.IsAllDigits()
What would you expect ret to be, True or False?
Currently IsAllDigits is returning True which I think is incorrect. If it is not wrong can someone explain the logic/reasoning behind it?
Thanks.
st.SetValue(‘’)
ret = st.IsAllDigits()
What would you expect ret to be, True or False?
Currently IsAllDigits is returning True which I think is incorrect. If it is not wrong can someone explain the logic/reasoning behind it?
Thanks.
By the look of the method comments, TRUE is expected.
!--------------------------------------------------------------------------------------------
! Returns True if the string does not contain any non-digit characters (ie. only '0' to '9')
! or False otherwise. If empty (zero length) string then returns true.
StringTheory.IsAllDigits Procedure(Long pStart=1, Long pEnd=0) !, bool
Mark
Ahhh. Missed that part in the source. I was reading just the html docs.
"Returns True if the string only contains digit characters (‘0’ to ‘9’). "
Thank you .
report this to capesoft - he will update docs i am sure
While looking for a different approach, I found the following,
st.SetValue(‘’)
st.IsAll(‘012345689’) returns False
st.IsDigit(1) returns False
st.IsDigit(0) returns False
st.IsAllDigits() returns True !Documented to do this
The html docs do say that IsAllDigits is equivalent to IsAll(‘0123456789’)
Returns True if the string only contains digit characters (‘0’ to ‘9’). this is the equivalent of calling
self.IsAll(‘01233456789’)
I guess it is just a matter of expecting consistency between the different methods and not understanding how an empty string could be considered to be all digits.
Hi John
yes I have had several discussions with Bruce about this in the past and we have different opinions and I think we ultimately decided to “agree to disagree”?? ST is Capesoft’s product so Bruce gets to decide.
Bruce’s thinking is that isAllDigits should return true unless there is an “offending” non-digit present. An empty string by definition has no characters so has no “offending” characters so should return true. So it is effectively “contains no non-digits”.
My thinking was that an empty string in this context could be thought of as equivalent to one or more spaces so isAllDigits would return false. Also it just felt intuitively wrong (to me) that something with no digits could be “all digits”.
So you can argue both ways, but at the end of the day it is what it is and you just need to be aware of it. (Or you can lobby Bruce to relent and change it! ha ha)
regarding isDigit, the parameter is the position so
st.setValue('abc123')
st.isdigit(1) ! false ('a')
st.isdigit(4) ! true ('1')
if your position is out of bounds it is false.
st.isdigit(0) ! false (valid positions are 1 to 6)
st.isdigit(7) ! false
cheers
Geoff R
Perhaps there needs to be a new IsOnlyDigits
method that does what you’re expecting. In this situation, a blank string is not “only digits”.
I just code around it once i knew its point of view
If Str.Length() and str.IsAllDigits()
And that is what I did! Now it works like I expect.
The typical NULL problem for a language that does not fully support NULLs?