[Swift-devel] Join function?

David Kelly davidk at ci.uchicago.edu
Tue Apr 3 13:33:06 CDT 2012


I think that would work, but it requires knowing the number of elements.

----- Original Message -----
> From: "Jonathan Monette" <jonmon at mcs.anl.gov>
> To: "David Kelly" <davidk at ci.uchicago.edu>
> Cc: "swift-devel at ci.uchicago.edu Devel" <swift-devel at ci.uchicago.edu>
> Sent: Tuesday, April 3, 2012 1:21:32 PM
> Subject: Re: [Swift-devel] Join function?
> So @strcat(a[0],":", a[1], ":", a[2], ":", a[3]); does not work? That
> is the only swift way I can think of to make it work. The only other
> approach is to use an app call to a perl/python script.
> 
> On Apr 3, 2012, at 1:02 PM, David Kelly wrote:
> 
> > Hello,
> >
> > Is there a way to concatenate all elements of an array into a single
> > string? I would also like to define a separator between elements. I
> > was thinking of something similar to Perl's join function.
> >
> > If I have:
> >
> > string a[];
> > a[0] = "this";
> > a[1] = "is";
> > a[2] = "a";
> > a[3] = "test";
> >
> > How can I get it into "this is a test" or "this:is:a:test"? @strcat
> > returns a reference. I can tracef with %q and get
> > "[this,is,a,test]", but it doesn't give me any control over the
> > formatting as far as I know.
> >
> > I could call a shell script to do this, just wondering if there was
> > another way.
> >
> > David
> > _______________________________________________
> > Swift-devel mailing list
> > Swift-devel at ci.uchicago.edu
> > https://lists.ci.uchicago.edu/cgi-bin/mailman/listinfo/swift-devel



More information about the Swift-devel mailing list