On 1/22/06, Jonas Maebe <[EMAIL PROTECTED]> wrote: > > On 22 Jan 2006, at 11:24, ik wrote: > > >> val(x,code); > >> result:=(code=0) and (posexset(['+','-'],x)=0) > >> > >> would already do. (untested from memory) > > > > And why is that better ? > > Because it reuses existing code (although the above could even be > made shorter by using TryStrToInt or so). Reusing existing code is > pretty much always better, because it improves maintainability, > reduces the chance to bugs and keeps the code size smaller.
But wouldn't a too large "number" such as 123456789012345678901234567890 would failed when using with TryStrToInt, and will work on a loop based checking for number characters ? And what if the string is empty ? There are so many ways to make it to fail, while actually try to see if the chars exists will not. If you really want a speed, while not to use regex and check something like ^\d+$ and get over with it ? You assuming that the only input you are getting will be a number or a char that is not a number. Do you have any other basic ways to make it "maintainable" and fast that can also support large amount of characters ? > > > I do a loop and see if I only have the valid > > chars or stop. What happen if I have a number with 20 or 50 chars > > based ? I only want to check if it contains a valid number chars, not > > to actually convert it to anything (no one promise you that you can > > convert it to any existed type!). > > I really don't think this is something which is needed in an rtl unit. I think that we should have some type of a large group of useful units on FPC that come with the "compiler" like Sun does with Java. It might go to contrib etc... I just thought that strutils is a good place for it. > Jonas Ido _______________________________________________ fpc-devel maillist - fpc-devel@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-devel