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 11/10/11 at 6:53 AM, adeyoung at andrew.cmu.edu (Andrew DeYoung)
wrote:

>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?

In[1]:= data = ToString /@ Range[3];

In[2]:= StringJoin @@ Riffle[data, " "]

Out[2]= 1 2 3

For what it is worth, I've been using Mathematica on a daily
basis for the past 10-20 years. And the only times I can recall
using For were to show someone just how much slower code runs in
Mathematica when using For instead of functional programming.




  • Prev by Date: Re: Converting a list of strings to a single space-delimited string
  • Next by Date: Re: Converting a list of strings to a single
  • 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