How do I convert an array of char to a string?
I have a normal array of characters and I want to convert its values to string. How can I do this?
Edit: Originally this question asked about "array of string to string", but the OP accepted an answer that said "array of char, to string".
It seems that perhaps you have text in an array of char
. If so then you can do this:
function ArrayToString(const a: array of Char): string;
begin
if Length(a)>0 then
SetString(Result, PChar(@a[0]), Length(a))
else
Result := '';
end;
On the other hand, maybe you're asking a completely different question.
function ArrayToString(const Data: array of string): string;
var
SL: TStringList;
S: string;
begin
SL := TStringList.Create;
try
for S in Data do
SL.Add(S);
Result := SL.Text;
finally
SL.Free;
end;
end;
This is how I understand what you are asking. It could be that David's solution is what you want, however. You decide.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With