Recent

Author Topic: Measurement converter in Pascal  (Read 1502 times)

Zvoni

  • Hero Member
  • *****
  • Posts: 1339
Re: Measurement converter in Pascal
« Reply #15 on: March 17, 2022, 11:44:25 am »
Code: Pascal  [Select][+][-]
  1. program Project1;
  2. Uses SysUtils;
  3. Const
  4.   SomeText:String='I am running 4.5 miles every day';
  5.   mTok:Double=1.609;
  6.  
  7. Var
  8.   a:TStringArray;
  9.   i:Integer;
  10.   d:Double;
  11.   s:String;
  12.   fs:TFormatSettings;
  13.  
  14. begin
  15.   fs:=DefaultFormatSettings;
  16.   a:=SomeText.Split(' ');
  17.   For i:=Low(a) To High(a) Do
  18.     Begin
  19.       If a[i].Trim='miles' Then
  20.         Begin
  21.           If Not TryStrToFloat(a[i-1],d,fs) Then
  22.             If fs.DecimalSeparator='.' Then
  23.               fs.DecimalSeparator:=','
  24.             Else
  25.               fs.DecimalSeparator:='.';
  26.           a[i-1]:=FloatToStr((StrToFloat(a[i-1],fs)*mTok),fs);
  27.           a[i]:='kilometers';
  28.         end;
  29.     end;
  30.   s:=s.Join(' ',a);
  31.   Writeln(s);
  32. end.  
  33.  
Returns:
Quote
I am running 7.2405 kilometers every day
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad

dzoole

  • New member
  • *
  • Posts: 8
Re: Measurement converter in Pascal
« Reply #16 on: March 17, 2022, 12:12:50 pm »
Zvoni your code seems fine in Lazarus Syntax check OK.
When I compile get succes but 1 warning.
I saved your file as .pas
Copy to Pascal Scripts folder in Subtitle Workshop
and when i want to use it i get SystemUtils not identified.
This Subtitle Workshop is very tricky with pascal scripts. Some pascal scripts works fine in 2.51 version but not good in other versions. 6.0a and 6.0b/e

 

TinyPortal © 2005-2018