开发者

Convert Array of Char to String? [closed]

开发者 https://www.devze.com 2023-04-01 07:11 出处:网络
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical andcannot be reasonably answered in its current form. For help clari
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 11 years ago.

How 开发者_StackOverflow社区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.

0

精彩评论

暂无评论...
验证码 换一张
取 消