How can I grab first two charaters from a text box?

Hello experts,

  OK this is a simple question. How can I grab the first two characters from a text box and put them into a string variable? The values will be something like 10.17 or 5.89 maybe just .50  What I want are the values the come before the decimal point and if there is nothing before it then 0 is what my string should have.

Thank you,
MrError
MrErrorAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

kretzschmarCommented:
hi MrError,

a function which so both

//Function for split strings
function SplitIt(Splitter : String;
                 Var ToSplit : String) : String;
Var P : Integer;
begin
  P := Pos(Splitter, ToSplit);
  If P = 0 then P := Length(ToSplit)+1;
  Result := Copy(ToSplit,1,p-1);
  ToSplit := Copy(ToSplit,p+length(splitter),MaxLongInt);
end;

example

mayAfter := MyHoleString;
myBefore := SplitIt('.',MyAfter);

MyAfter holds now only this after the point
(or was it Otherwise)

meikl
0
florisbCommented:
Simple as she is, two edit's on form and it should work.

Greetings,
F-)

procedure TForm1.Button1Click(Sender: TObject);
var
s : string;
begin
//test value in edit1?

//do
if pos('.',edit1.text) = 0 then
  s := edit1.text
else
  s := Copy(edit1.text, 0, pos('.',edit1.text)-1);

//if value like .xxx
if s = '' then
  s := '0';
//there's your string.
edit2.text := s;
end;
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
florisbCommented:
Sorry Guys, I filled in an answer when there was no comment yet...

What now? Is this why I never should propose answers and only comments, hmmmm

F-?
0
MrErrorAuthor Commented:
Florisb & meikl,

  Both of your ideas work. Thank you for your help. It is better to post comments and let the questioner to accept as an answer because more people look at your question. But oh well not a big deal.   Thank you for giving your answer. Meikl I will give you points on the other question you answered -two days ago.

MrError
0
florisbCommented:
Tanx, I'll comment now...
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.