开发者

Convert Array of Char to String? [closed]

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜