Jump to content

Recommended Posts

Good Day,
MyVar could be just '22-1'  or could be '22-1, 22-2'  or could be  '22-1, 22-2, 22-3' or more i dont know

but always there is a comma ( , )   between the str numbers

I'll use these str numbers in a Sql like  .... WHERE DOCNOS IN ('22-1', '22-2', ....)

My Problem is

1= I don't know how many str numbers there are in MyVar

2= How to add QuotedStr into each document str number for sql where in
Thank You

Share this post


Link to post

How about something like TStringHelper.Split ?

use
    System.SysUtils
  , System.Generics.Collections
  ;

...

var
  LInput  : String;
  LArray  : TArray<String>;
  LElem   : String;
  LStrQuo : String;
begin
  LInput := '22-1, 22-2, 22-3';
  LArray  := LInput.Split( [ ',' ], TStringSplitOptions.ExcludeEmpty );  // Ignore empty elements
  
  for LElem in LArray do
  begin
      LStrQuo := LElem.Trim.QuotedString( '"' );
      ... // Do something with the quoted in SQL
  end;
end.

 

Edited by Rollo62
  • Like 3

Share this post


Link to post
if ContainsText(LInput, ' ') then  LInput := StringReplace(LInput,' ','',[rfReplaceAll]);

Maybe you have to remove the SPACE character, before you put everything into array.

 

Edited by skyzoframe[hun]

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×