By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,682 Members | 1,999 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,682 IT Pros & Developers. It's quick & easy.

A more useful Split?

P: n/a
mb
I was wondering if there is an easy, more useful Split function that will
split with a string delimiter like "<>" or "////"?
Nov 16 '05 #1
Share this Question
Share on Google+
10 Replies


P: n/a
Hi mb:

You can use the Split method of the Regex class:
http://msdn.microsoft.com/library/de...plitTopic3.asp

--
Scott
http://www.OdeToCode.com

On Sat, 25 Sep 2004 10:07:21 -0600, "mb" <mm@hotmail.com> wrote:
I was wondering if there is an easy, more useful Split function that will
split with a string delimiter like "<>" or "////"?


Nov 16 '05 #2

P: n/a
"mb" <mm@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
I was wondering if there is an easy, more useful Split function that will
split with a string delimiter like "<>" or "////"?


using System.Text.RegularExpressions;

string strTest = "One<>Two<>Three<>Four<>Five";
string[] astrTest = Regex.Split(strTest, "<>");


Nov 16 '05 #3

P: n/a
mb
THANKS!!

By the way, what does Regex stant for. I keep calling it "Rejects" :-)

"Mark Rae" <ma**@mark-N-O-S-P-A-M-rae.co.uk> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
"mb" <mm@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
I was wondering if there is an easy, more useful Split function that will
split with a string delimiter like "<>" or "////"?


using System.Text.RegularExpressions;

string strTest = "One<>Two<>Three<>Four<>Five";
string[] astrTest = Regex.Split(strTest, "<>");

Nov 16 '05 #4

P: n/a

"mb" <mm@hotmail.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
THANKS!!

By the way, what does Regex stant for. I keep calling it "Rejects" :-)

REGular EXpressions
"Mark Rae" <ma**@mark-N-O-S-P-A-M-rae.co.uk> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
"mb" <mm@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
>I was wondering if there is an easy, more useful Split function that
>will
> split with a string delimiter like "<>" or "////"?


using System.Text.RegularExpressions;

string strTest = "One<>Two<>Three<>Four<>Five";
string[] astrTest = Regex.Split(strTest, "<>");


Nov 16 '05 #5

P: n/a
mb
Is this faster than the string.Split method?
"Daniel O'Connell [C# MVP]" <onyxkirx@--NOSPAM--comcast.net> wrote in
message news:eI*************@TK2MSFTNGP10.phx.gbl...

"mb" <mm@hotmail.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
THANKS!!

By the way, what does Regex stant for. I keep calling it "Rejects" :-)


REGular EXpressions
"Mark Rae" <ma**@mark-N-O-S-P-A-M-rae.co.uk> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
"mb" <mm@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
>I was wondering if there is an easy, more useful Split function that
>will
> split with a string delimiter like "<>" or "////"?

using System.Text.RegularExpressions;

string strTest = "One<>Two<>Three<>Four<>Five";
string[] astrTest = Regex.Split(strTest, "<>");



Nov 16 '05 #6

P: n/a
You could implement your own splitting function.
Here's one I have done on a hurry that is ugly but working:

public static string[] StringSplit(string input, string delimiter)
{
ArrayList arr = new ArrayList();

int pos = -1;
int acheived = 0;
bool founddelimiter = false;
StringBuilder splitted = new StringBuilder();
StringBuilder temp = new StringBuilder();

while ( pos++ < input.Length -1 )
{
if ( input[pos] != delimiter[acheived] )
{
founddelimiter = false;
splitted.Append(temp.ToString());
splitted.Append( input[pos] );
acheived = 0;
temp.Length = 0;
}
else
{
if ( acheived == delimiter.Length - 1 )
{
temp.Length = 0;
arr.Add( splitted.ToString() );
founddelimiter = true;
splitted.Length = 0;
acheived = 0;
}
else
{
temp.Append(input[pos]);
acheived++;
}
}
}

if ( splitted.Length > 0 )
arr.Add( splitted.ToString() );

if ( founddelimiter )
arr.Add("");

return (string[]) arr.ToArray(typeof(string));

}

"mb" <mm@hotmail.com> wrote in message
news:#E**************@TK2MSFTNGP10.phx.gbl...
I was wondering if there is an easy, more useful Split function that will
split with a string delimiter like "<>" or "////"?

Nov 16 '05 #7

P: n/a
"mb" <mm@hotmail.com> wrote in message
news:OK**************@TK2MSFTNGP12.phx.gbl...
Is this faster than the string.Split method?


I doubt it, but you don't have a lot of choice in this instance because the
string.Split method won't accept multiple characters to split on. Your only
other option is to write your own splitting function...
Nov 16 '05 #8

P: n/a
"mb" <mm@hotmail.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
THANKS!!

By the way, what does Regex stant for. I keep calling it "Rejects" :-)


The clue is in the namespace...

using System.Text.RegularExpressions;
Nov 16 '05 #9

P: n/a
mb,
In addition to the other comments.

There are three Split functions in .NET:

Use Microsoft.VisualBasic.Strings.Split if you need to split a string based
on a specific word (string). It is the Split function from VB6.

Use System.String.Split if you need to split a string based on a collection
of specific characters. Each individual character is its own delimiter.

Use System.Text.RegularExpressions.RegEx.Split to split based
on matching patterns.
By referencing the Microsoft.VisualBasic assembly in C# you can use the
Strings.Split function to split a string based on a word.

Something like:
string str = "one<>two<>three"; string [] fields = Strings.Split(str, "<>", -1,
CompareMethod.Binary);
Hope this helps
Jay
"mb" <mm@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...I was wondering if there is an easy, more useful Split function that will
split with a string delimiter like "<>" or "////"?

Nov 16 '05 #10

P: n/a
"mb" <mm@hotmail.com> wrote in message news:<OK**************@TK2MSFTNGP12.phx.gbl>...
Is this faster than the string.Split method?


Probably not, but is far more versatile.
Nov 16 '05 #11

This discussion thread is closed

Replies have been disabled for this discussion.