MathGroup Archive 2011

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Converting a list of strings to a single space-delimited string


On Nov 10, 11:02 pm, Andrew DeYoung <adeyo... at andrew.cmu.edu> wrote:
> Hi,
>
> I know that the command StringSplit can be used to convert a single
> space-delimited string to a list of strings.  For example,
>
> B = "1 2 3";
> mylist = StringSplit[B]
>
> gives a list mylist such that mylist = {"1", "2", "3"}.
>
> But what if I would like to go in the reveres direction -- convert
> {"1", "2", "3"} to "1 2 3"?  Is there a good way to do this, other
> than using a For loop and concatenating the elements of the list
> together?
>
> Thanks so much.
>
> Andrew DeYoung
> Carnegie Mellon University

there are a few ways to do it but this is probably easiest:

list = {"1", "2", "3"};
spacer= " ";

StringJoin@Riffle[list, spacer]

Mike



  • Prev by Date: Re: Converting a list of strings to a single
  • Next by Date: Re: nVidia Optumus prevents using CUDA?
  • Previous by thread: Re: Converting a list of strings to a single space-delimited string
  • Next by thread: Re: Converting a list of strings to a single space-delimited string