Search code examples
delphidelphi-7delphi-xe2

How do I put apostrophes in a string?


I have a widestring say StringABC I have an array say ArrayABC, elements of this array are

ArrayABC[0]='A';
ArrayABC[1]='B';
ArrayABC[2]='C';

Now I have to make stringABC as StringABC := ''A','B','C'';

I am trying to do this like

StringABC := '';
for (i:=0 to 2) do
begin
StringABC := StringABC + ArrayABC[i] + ',';
if i = 2
stringABC := StringABC + ArrayABC[i];
end

I am getting result as stringABC = 'A,B,C' but not ''A','B','C'' What should I improve in my code?


Solution

  • StringABC := '';
    for (i:=0 to 2) do
    begin
    StringABC := StringABC + '''' + ArrayABC[i] + ''',';
    if i = 2
    stringABC := StringABC + '''' + ArrayABC[i] + '''';
    end
    

    Although I would just concatenate with the comma for all i, then al the end remove the final comma.