How to modify this code? lazarus / 61-Beginners ---------------------------------------------------------------------- Doe · 2021-01-30 14:35 Hello guys, I was trying to split a text such as "Initial velocity = 10", and assign 10 into a variable. I want to modify it so if the user inputs "Initiavelocity=10" or "initial velocity=10" or even "IV=10". It can perform the same function. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i unit InputUVAforT; {$mode objfpc}{$H+} interface uses  Classes, SysUtils, Forms, Controls, Graphics, Dialogs, Menus, strutils, StdCtrls; type   { TInputUVAforT }   TInputUVAforT = class(TForm)    Button1: TButton;    Label1: TLabel;    Values: TMemo;    procedure Button1Click(Sender: TObject);  private   public   end; var  FInputUVAforT: TInputUVAforT;  i:integer;  A: TStringArray;  toxt,Vr: string;  InatialV,FinalV,Acceleration:real; implementation {$R *.lfm} { TInputUVAforT } procedure TInputUVAforT.Button1Click(Sender: TObject);begin  for i:=0 to Values.lines.count-1 do      begin         toxt:=Values.lines[i];         toxt:=DelSpace(toxt);         A:= toxt.Split('=');         if (A[0]='Initialcelocity') then         begin         InatialV:=StrToFloat(A[1]);         end         else if A[0]='Finalvelocity' then         begin         FinalV:=StrToFloat(A[1]);         end         else if A[0]='Acceleration' then         begin         Acceleration:=StrToFloat(A[1]);         end         end;      showmessage(FloatToStr(InatialV));      showmessage(FloatToStr(FinalV));      showmessage(FloatToStr(Acceleration));end; end. ---------------------------------------------------------------------- Nitorami · 2021-01-30 15:55 Either compare your A[0] to a list of allowed strings, or try do do it via some string similarity algorithm. See e.g. wikipedia "string metric". I don't know if the fcl implements any such algorithm, and it may be risky to rely on it. Your strings "InitialVelocity" and "FinalVelocity" are somewhat similar, and certainly closer to each other than "InitialVelocity" to "IV". So the best option is presumably a lookup list. You may wish to convert your input string to uppercase first to reduce the number of valid strings you have to define. ---------------------------------------------------------------------- Bart · 2021-01-30 16:14 Please do NOT make new posts for, wgat is in essence the same problem you have already posted at least once. Bart ---------------------------------------------------------------------- Peter H · 2021-01-30 16:15 Instead an if else if... chain a "case of" construct would be simpler: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i {$mode objfpc}var s: string;begin  case s of    'abc',  'xyz', '123': s := '123';    '111': s := '';  else    ShowMessage(s+':error');  end;end. BTW, you posted the same problem here, https://forum.lazarus.freepasca l.org/index.php/topic,53111.msg392436.html#msg392436, dont open a new thread. Others have critizized the use of TMemo. Of course TMemo has the advantage, you can cut and paste text from/to other compatible applications. This is solely your decision. ---------------------------------------------------------------------- lucamar · 2021-01-30 16:18 To disregard the case of the string, you can use CompareText() instead of testing for equality: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i {Instead of:         if (A[0]='Initialcelocity') then ...}         if CompareText(A[0], 'Initialvelocity') = 0 then ... Testing for alternative names might be a little more complex, though not much. If they are few (as in just "IV" for "Initial Velocity" and so on) you can do it by expanding the if expression: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i   if (AnsiCompareText(A[0], 'initialvelocity') = 0)  or (AnsiCompareText(A[0], 'iv') = 0) then ... Note also that instead of a series of if ... then else if ... you can use a case statement, which might be better optimized by the compiler and allows you to simplify your code a lot : Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TInputUVAforT.Button1Click(Sender: TObject);begin  for i:=0 to Values.lines.count-1 do  begin    toxt := lowercase(Values.lines[i]);    toxt:=DelSpace(toxt);    A:= toxt.Split('=');    case A[0] of    'initialvelocity', 'iv'): InatialV:=StrToFloat(A[1]);    'finalvelocity', 'fv': FinalV:=StrToFloat(A[1]);    'acceleration': Acceleration:=StrToFloat(A[1]);    end;  end;  showmessage(FloatToStr(InatialV));  showmessage(FloatToStr(FinalV));  showmessage(FloatToStr(Acceleration));end; ETA:Quote from: Bart on January 30, 2021, 05:14:19 pmPlease do NOT make new posts for, wgat is in essence the same problem you have already posted at least once. Sorry, hadn't seen your post. Neither have I seen the (original?) post you refer to, to be honest EATA: Never mind, I've just seen it: How to split a text and get value from it? ---------------------------------------------------------------------- trev · 2021-01-30 23:08 Duplicated post - do NOT do this! See: https://forum.lazarus.freepascal.org/index.php/topic,53111.0.html