|
 |
aspx thread: Joining items in an array
Message #1 by "Julian Roberts" <jules@c...> on Thu, 27 Dec 2001 00:16:52 -0000
|
|
I can split a string into an array:
string myString="this,is,a,test";
char[] separator={","};
string[] myWords;
myWords=myString.Split(separator);
but I can't figure out how to do the other way round. ie. Join the items in
an array into a string.
Julian Roberts
http://charon.co.uk
Message #2 by "Dan Green" <dan@d...> on Fri, 28 Dec 2001 10:17:50 +1100
|
|
Julian,
Actually you already know. :)
It's the static overloaded method, String.Join()
Dan Green
[ http://dotnetdan.com -- putting the dan in .net ]
> -----Original Message-----
> From: Julian Roberts [mailto:jules@c...]
> Sent: Thursday, 27 December 2001 11:17 AM
> To: ASP+
> Subject: [aspx] Joining items in an array
>
> ---
> Need a present for your favorite programmer?
> E-Documents from Amazon.com at http://p2p.wrox.com/edocs.asp
> ---
> I can split a string into an array:
>
> string myString="this,is,a,test";
> char[] separator={","};
> string[] myWords;
> myWords=myString.Split(separator);
>
> but I can't figure out how to do the other way round. ie. Join the
items
> in
> an array into a string.
>
> Julian Roberts
> http://charon.co.uk
>
>
>
Message #3 by "Julian Roberts" <jules@c...> on Fri, 28 Dec 2001 15:15:48 -0000
|
|
Thanks Dan, I think I'd confused myself on this one. Maybe it was because VS
intellisense wasn't showing it. But now I can see it my book. Anyway, I've
another question for you, if you don't mind? How can I split a string based
on multicharacter delimiters. For example, my delimiter is ##. The code
below produces erratic results. It seems to me that using the Split function
only accepts an array of single characters.
string myString="this##is##a##test";
char[] separator={"#","#"};
string[] myWords;
myWords=myString.Split(separator);
Julian Roberts
http://charon.co.uk
----- Original Message -----
From: "Dan Green" <dan@d...>
To: "ASP+" <aspx@p...>
Sent: Thursday, December 27, 2001 11:17 PM
Subject: [aspx] RE: Joining items in an array
> Julian,
>
> Actually you already know. :)
> It's the static overloaded method, String.Join()
>
Message #4 by "Dan Green" <dan@d...> on Sat, 29 Dec 2001 08:49:36 +1100
|
|
Use String.Split with char delimiters, Regex.Split with string
delimeters.
Here's an example of using Regex.Split...
<code buildString="csc /r:System.dll ...">
using System;
using System.Text.RegularExpressions;
public class Test
{
public static void Main()
{
Console.WriteLine("{0}{1}",Regex.Split("a##b", "##"));
}
}
</code>
Dan Green
[ http://dotnetdan.com -- putting the dan in .net ]
> -----Original Message-----
> From: Julian Roberts [mailto:jules@c...]
> Sent: Saturday, 29 December 2001 2:16 AM
> To: ASP+
> Subject: [aspx] RE: Joining items in an array
>
> Thanks Dan, I think I'd confused myself on this one. Maybe it was
because
> VS
> intellisense wasn't showing it. But now I can see it my book. Anyway,
I've
> another question for you, if you don't mind? How can I split a string
> based
> on multicharacter delimiters. For example, my delimiter is ##. The
code
> below produces erratic results. It seems to me that using the Split
> function
> only accepts an array of single characters.
>
> string myString="this##is##a##test";
> char[] separator={"#","#"};
> string[] myWords;
> myWords=myString.Split(separator);
>
>
> Julian Roberts
> http://charon.co.uk
>
>
>
> ----- Original Message -----
> From: "Dan Green" <dan@d...>
> To: "ASP+" <aspx@p...>
> Sent: Thursday, December 27, 2001 11:17 PM
> Subject: [aspx] RE: Joining items in an array
>
>
> > Julian,
> >
> > Actually you already know. :)
> > It's the static overloaded method, String.Join()
> >
>
>
>
>
Message #5 by "Julian Roberts" <jules@c...> on Fri, 28 Dec 2001 23:08:06 -0000
|
|
Thanks Dan, I'll give that a shot. I'm slowly but surely getting my head
around OOP.
Julian Roberts
http://charon.co.uk
----- Original Message -----
From: "Dan Green" <dan@d...>
To: "ASP+" <aspx@p...>
Sent: Friday, December 28, 2001 9:49 PM
Subject: [aspx] RE: Joining items in an array
> Use String.Split with char delimiters, Regex.Split with string
> delimeters.
> Here's an example of using Regex.Split...
>
> <code buildString="csc /r:System.dll ...">
>
> using System;
> using System.Text.RegularExpressions;
>
> public class Test
> {
> public static void Main()
> {
> Console.WriteLine("{0}{1}",Regex.Split("a##b", "##"));
> }
Message #6 by "Julian Roberts" <jules@c...> on Sun, 30 Dec 2001 01:15:36 -0000
|
|
Hi Dan, thanks for the tip about using RegularExpressions. Everything works
fine now.
Julian Roberts
http://charon.co.uk
----- Original Message -----
From: "Dan Green" <dan@d...>
To: "ASP+" <aspx@p...>
Sent: Friday, December 28, 2001 9:49 PM
Subject: [aspx] RE: Joining items in an array
> Use String.Split with char delimiters, Regex.Split with string
> delimeters.
> Here's an example of using Regex.Split...
|
|
 |