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?

[Webinar] Streamline your web hosting managementRegister Today

x
 
florisbConnect With a Mentor Commented:
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
 
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:
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
All Courses

From novice to tech pro — start learning today.