[Swift-user] Concatenating members of a string array

Michael Wilde wilde at mcs.anl.gov
Tue Aug 28 15:04:24 CDT 2012


Sheri, in response to your off-list question:  here's two ways to concatenate a string array into a single string. We should provide a primitive to do this better / more reliably.

The code below is a quick hack and needs polishing for the User Guide.

- Mike


string sa[] = ["aaa","bbb","ccc","ddd","eee"];

string cs[];

cs[-1] = "";

foreach e,i in sa {
  cs[i] = @strcat(cs[i-1], " ", e);
}

trace("cat=",cs[@length(sa)-1]);

type file;

app (file o) echo (string s[])
{
  echo s stdout=@filename(o);
}

file f = echo(sa);

string os = readData(f);

trace("os=",os);



More information about the Swift-user mailing list