| TIP: Click on subject to list as thread! | ANSI |
| echo: | |
|---|---|
| to: | |
| from: | |
| date: | |
| subject: | StringToInteger |
Hi Bob,
And thus Bob let it be known to David:
BL>> my string is just a number with junk I don't care about
BL>> following it.
BL>> function StrInt(s: string): integer;
BL>> var
BL>> i, size: integer;
BL>> begin
BL>> i := 1; size := 0;
BL>> while s[i] in ['0'..'9'] do begin
BL>> size := size * 10 + (Ord(s[i]) - 48);
BL>> inc(i);
BL>> end;
BL>> StrInt := size;
BL>> end;
DD>> Check out VAL()
BL> VAL() gets upset by the junk following the numbers in the string. If
BL> I strip[ the junk and run val() on the new string, it takes longer.
BL> If I go val('223 Sheep Street'); I get zero and a fault at 4. Val
BL> can't handle the Sheep.
Val is good for checking if the string entered in is an integer..
ie
var
CheckNum: string;
Number,ErrorCode: integer;
begin
WriteLn('Enter Number');
ReadLn(CheckNum);
val (CheckNum,Number,ErrorCode);
if ErrorCode = 1 then
WriteLn('Not an integer');
end.
Other than that the only way to convert your string to an integer is to
make sure that the string is an integer anyway.
Your function isn't that slow is it??
Cya,
Pete
... Computers don't make mistakes, but foolish people do.
--- FMail/386 1.02+
* Origin: Back from Reality. Mail. Files if you can find them! (3:635/309)SEEN-BY: 633/267 270 @PATH: 635/309 727 633/267 |
|
| SOURCE: echomail via fidonet.ozzmosis.com | |
Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.