?
Solved

break 2 element string into int and string

Posted on 1999-01-12
3
Medium Priority
?
156 Views
Last Modified: 2010-04-06
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
0
Comment
Question by:hoffb
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 20

Accepted Solution

by:
Madshi earned 80 total points
ID: 1356151
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.

Regards, Madshi.
0
 
LVL 5

Expert Comment

by:heathprovost
ID: 1356152
Damn, beat me to it.... Yours is better anyway so I wont bother :)

Heath
0
 

Author Comment

by:hoffb
ID: 1356153
I'll try it.  Fast Answer!
0

Featured Post

Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Suggested Courses
Course of the Month14 days, 20 hours left to enroll

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question