# break 2 element string into int and string

Reading a line from file that has two elements, first bit of data is price, and 2nd is part description.  These two elements are separated by spaces.  How do I grab the first piece of the line and convert to integer? Example line record below.
\$100.00     Range Hood
###### Who is Participating?

Commented:
Try this:

function ConvertToPriceAndDescr(str: string; var price: integer; var descr: string) : boolean;
begin
result:=false;
Trim(str);
i1:=Pos(' ',str);
descr:=Copy(str,i1,maxInt);
Trim(descr);
Delete(str,i1,maxInt);
i1:=1;
while (i1<=length(str)) and (not (str[i1] in ['0'..'9'])) do
inc(i1);
Delete(str,1,i1-1);
i1:=Pos('.',str);
try
price:=StrToInt(Copy(str,1,i1-1))*100 + StrToInt(Copy(str,i1+1,maxInt));
except exit end;
result:=true;
end;

In your example the result would be: "price=10000" and "descr='Range Hood'". To get the cents, devide price with 100.

0

Commented:
Damn, beat me to it.... Yours is better anyway so I wont bother :)

Heath
0

Author Commented: