From: Zach on
On 22/03/2010 12:07, Family Tree Mike wrote:
> On 3/22/2010 6:40 AM, Zach wrote:
>> On 22/03/2010 11:35, Andy O'Neill wrote:
>>>
>>> "Zach" <xx.xx(a)xx> wrote in message
>>> news:4ba74399$0$28141$5fc3050(a)news.tiscali.nl...
>>>> On 22/03/2010 11:12, Zach wrote:
>>>>> Using blabla.Split(whatever) you can split up a text-line into its
>>>>> constituent elements of an array (as you will know well), my question:
>>>>> is there code to do the opposite, say after you have nullified one of
>>>>> the elements of the array? Please give simple example, no reference or
>>>>> lecture.
>>>>>
>>>>> Many thanks,
>>>>> Zach.
>>>>>
>>>>>
>>>>>
>>>> PS I am aware that you can stick the elements together in a loop but
>>>> that is not what I am after.
>>>>
>>>> Zach
>>>
>>> On the face of it, iterating through your array or collection of words
>>> and concatenating non-null entries onto a stringbuilder in a loop would
>>> be the way to do it.
>>> What's the problem with that?
>>
>> Well, there is nothing wrong with that, true, but given the Split
>> option, I thought there might be an opposite of Split. Because you don't
>> need Split, to split up a string, code not so complicated to do that
>> either :)
>>
>> Zach
>
> It sounds like you are looking for string.Join(token, items []);
>
> http://msdn.microsoft.com/en-us/library/57a79xd0.aspx
>
Very good. Many thanks.
Zach
From: Steve Thackery on

"Family Tree Mike" <FamilyTreeMike(a)ThisOldHouse.com> wrote in message
news:u73Ch$ayKHA.2552(a)TK2MSFTNGP04.phx.gbl...

> It sounds like you are looking for string.Join(token, items []);

You know, it amazes me just what is hiding away in the .Net libraries.
Fantastic, really.

SteveT

From: Peter Duniho on
Steve Thackery wrote:
>
> "Family Tree Mike" <FamilyTreeMike(a)ThisOldHouse.com> wrote in message
> news:u73Ch$ayKHA.2552(a)TK2MSFTNGP04.phx.gbl...
>
>> It sounds like you are looking for string.Join(token, items []);
>
> You know, it amazes me just what is hiding away in the .Net libraries.
> Fantastic, really.

Though, I'm not sure I would call a public method in the System.String
class, documented along with every other public method in the
System.String class, quite "hidden". :)

The OP might benefit from some practice simply reviewing the
documentation for the classes he is working with.

Pete
From: Andy O'Neill on

"Peter Duniho" <no.peted.spam(a)no.nwlink.spam.com> wrote in message
news:%23E34ISdyKHA.3304(a)TK2MSFTNGP06.phx.gbl...
> Steve Thackery wrote:
>>
>> "Family Tree Mike" <FamilyTreeMike(a)ThisOldHouse.com> wrote in message
>> news:u73Ch$ayKHA.2552(a)TK2MSFTNGP04.phx.gbl...
>>
>>> It sounds like you are looking for string.Join(token, items []);
>>
>> You know, it amazes me just what is hiding away in the .Net libraries.
>> Fantastic, really.
>
> Though, I'm not sure I would call a public method in the System.String
> class, documented along with every other public method in the
> System.String class, quite "hidden". :)
>
> The OP might benefit from some practice simply reviewing the documentation
> for the classes he is working with.
>
> Pete

What happens if one of the entries in an array you use join on is null?

From: Family Tree Mike on
On 3/22/2010 11:44 AM, Andy O'Neill wrote:
>
> "Peter Duniho" <no.peted.spam(a)no.nwlink.spam.com> wrote in message
> news:%23E34ISdyKHA.3304(a)TK2MSFTNGP06.phx.gbl...
>> Steve Thackery wrote:
>>>
>>> "Family Tree Mike" <FamilyTreeMike(a)ThisOldHouse.com> wrote in message
>>> news:u73Ch$ayKHA.2552(a)TK2MSFTNGP04.phx.gbl...
>>>
>>>> It sounds like you are looking for string.Join(token, items []);
>>>
>>> You know, it amazes me just what is hiding away in the .Net
>>> libraries. Fantastic, really.
>>
>> Though, I'm not sure I would call a public method in the System.String
>> class, documented along with every other public method in the
>> System.String class, quite "hidden". :)
>>
>> The OP might benefit from some practice simply reviewing the
>> documentation for the classes he is working with.
>>
>> Pete
>
> What happens if one of the entries in an array you use join on is null?

It works fine:

string[] items = new string[] { "Red", "Green", null, "Blue" };
string output = string.Join(",", items);

produces: Red,Green,,Blue

--
Mike