Marco van de Voort wrote 10 lines
> I wish to add 3 new string functions for strutils:
> 1. Check if a string is an integer (without + or - signs).
Hmm, is this not a bit overspecialisation ?
val(x,code);
result:=(code=0) and (posexset(['+','-'],x)=0)
would already do. (untested from memory)
And why is that better ? 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!).
> 2. split a string into an array using a giving separator.
In some form already exists. (e.g. tstringlist) however that has some
limitations.
I also did a TString based function that does the same (a long time ago.. my code is based on an old Delphi and TP unit I written), but as you said TString (descendant) also have it ...
However so has yours:
- separator aggregates are not supported.
Well it was made to be separated with one char, but you can add support to a string or a charset if you really want :)
- there is too much copy() ing going on.
I'm still looking for a way to know if a char exists even if the string is empty without any "Access Violation" errors... copy is the best hack I can think about, alto I thought today on a better way to do it ... maybe I'll rewrite it ...
I do agree however that such function, without tstringlists limitations is
needed, but we need something more general I think.
Can you tell me what exactly is needed ? I changed this functions from an old unit I made (as I written above), and I'm using it in my IP Calc unit (that I'm still writing).
One of the reasons I wish to see it appear on FPC is because some people actually interested in this unit, and thous people are not using FPC at all, so it can be a good place to start.
Ido