Prev: Generate value of control's property runtime
Next: Preserving character attributes in a RichTextBox
From: Andy O'Neill on 22 Mar 2010 12:13 "Family Tree Mike" <FamilyTreeMike(a)ThisOldHouse.com> wrote in message news:u$%23qkgdyKHA.2644(a)TK2MSFTNGP04.phx.gbl... <<>> >> 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 2 separators. Depends on what output is required for a null entry.
From: Family Tree Mike on 22 Mar 2010 13:15 On 3/22/2010 12:13 PM, Andy O'Neill wrote: > > "Family Tree Mike" <FamilyTreeMike(a)ThisOldHouse.com> wrote in message > news:u$%23qkgdyKHA.2644(a)TK2MSFTNGP04.phx.gbl... > <<>> >>> 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 > > 2 separators. > Depends on what output is required for a null entry. > // Looks like my last sent message errored out on the server. Yes, whether it works, depends on your definition of works. :) What I meant was, it produces a string, that when run through string.split(), faithfully reproduces the input list of strings. -- Mike
From: Arne Vajhøj on 22 Mar 2010 18:47 On 22-03-2010 13:15, Family Tree Mike wrote: > On 3/22/2010 12:13 PM, Andy O'Neill wrote: >> "Family Tree Mike" <FamilyTreeMike(a)ThisOldHouse.com> wrote in message >> news:u$%23qkgdyKHA.2644(a)TK2MSFTNGP04.phx.gbl... >>>> 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 >> >> 2 separators. >> Depends on what output is required for a null entry. > > // Looks like my last sent message errored out on the server. I got it. > > Yes, whether it works, depends on your definition of works. :) > > What I meant was, it produces a string, that when run through > string.split(), faithfully reproduces the input list of strings. And if the empty element is not wanted then there is the option of: string output = items.Aggregate((tot,nxt) => tot + (nxt != null ? "," + nxt : "")); Arne
First
|
Prev
|
Pages: 1 2 3 Prev: Generate value of control's property runtime Next: Preserving character attributes in a RichTextBox |