help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Equivalent of Perl 'join' ?


From: Sergei Steshenko
Subject: Re: Equivalent of Perl 'join' ?
Date: Thu, 16 Dec 2010 12:43:46 -0800 (PST)

--- On Thu, 12/16/10, bpabbott <address@hidden> wrote:

From: bpabbott <address@hidden>
Subject: Re: Equivalent of Perl 'join' ?
To: "Sergei Steshenko" <address@hidden>
Cc: "John W. Eaton" <address@hidden>, "CdeMills" <address@hidden>, 
address@hidden
Date: Thursday, December 16, 2010, 11:59 AM

On Dec 16, 2010, at 01:52 PM, Sergei Steshenko <address@hidden> wrote:
--- On Thu, 12/16/10, John W. Eaton <address@hidden> wrote:



> From: John W. Eaton <address@hidden>

> Subject: Re: Equivalent of Perl 'join' ?

> To: "Ben Abbott" <address@hidden>

> Cc: "CdeMills" <address@hidden>, address@hidden

> Date: Thursday, December 16, 2010, 10:17 AM

> On 16-Dec-2010, Ben Abbott wrote:

> 

> | If you'd like to preserve spaces ....

> | 

> |     strcat (strcat (LIST, EXPR){:})

> | 

> | For example ...

> | 

> |     c = {"a", "b", "c"};

> |     cstrcat (strcat (c, ";"){:})

> |     ans = a;b;c;

> 

> Another way:

> 

>   c = {"a", "b", "c"};

>   sprintf ("%s;", c{:})

> 

> jwe

> _______________________________________________

> Help-octave mailing list

> address@hidden

> https://www-old.cae.wisc.edu/mailman/listinfo/help-octave

> 



Not quite:



"

octave:1> c = {"a", "b", "c"};

octave:2> c

c =



{

  [1,1] = a

  [1,2] = b

  [1,3] = c

}



octave:3> sprintf ("%s;", c{:})

ans = a;b;c;

octave:4>

"



- the trailing ';' is redundant. I.e. Perl 'join' would produce



a;b;c


       I like John's solution. Assuming perl does not trim the spaces for the 
listed strings, and the last separator is to be removed ...
        join = @(expr,list) sprintf (sprintf ("%s%s", "%s", expr), 
list{:})(1:end-1);
Ben


-----------------------------------------------------------------------

Perl does not trim spaces in this case, i.e. the strings are joined without
any transformation.

Regards,
  Sergei.



      



reply via email to

[Prev in Thread] Current Thread [Next in Thread]