WT-Fakawi
02-18-2012, 10:09 AM
program test;
var
s:String;
begin
s:= 'This is a test';
Trim(s);
Writeln(s);
end.
I was assuming Trim removes spaces, but appearantly, I am doing something wrong.
I need this because I want to convert a string to a number '691 coins have been added to your pouch' or '691coins have been added to your pouch' (sometimes the space is gone) and keep 691. Got it working, except for the spaces error
program test;
var
text: String;
a, Number: Integer;
procedure Grabnumbers;
begin
text := '123 coins have been';
a := Pos('coins', text);
writeln('a = ' + IntToStr(a));
SetLength(Text, a - 2);
Writeln('text = ' + Text +']');
Trim(Text);
Writeln('trim = ' + Text +']');
Try
Number := StrToInt(Text)
Except // nothing for now, resulting in 0
end;
writeln('num = ' + IntToStr(Number));
end;
begin
Grabnumbers;
end.
tl: dr; How do you use Trim?
var
s:String;
begin
s:= 'This is a test';
Trim(s);
Writeln(s);
end.
I was assuming Trim removes spaces, but appearantly, I am doing something wrong.
I need this because I want to convert a string to a number '691 coins have been added to your pouch' or '691coins have been added to your pouch' (sometimes the space is gone) and keep 691. Got it working, except for the spaces error
program test;
var
text: String;
a, Number: Integer;
procedure Grabnumbers;
begin
text := '123 coins have been';
a := Pos('coins', text);
writeln('a = ' + IntToStr(a));
SetLength(Text, a - 2);
Writeln('text = ' + Text +']');
Trim(Text);
Writeln('trim = ' + Text +']');
Try
Number := StrToInt(Text)
Except // nothing for now, resulting in 0
end;
writeln('num = ' + IntToStr(Number));
end;
begin
Grabnumbers;
end.
tl: dr; How do you use Trim?