473,569 Members | 2,692 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

A more useful Split?

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
10 3510
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
"mb" <mm@hotmail.com > wrote in message
news:%2******** ********@TK2MSF TNGP10.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.Reg ularExpressions ;

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


Nov 16 '05 #3
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******** ********@TK2MSF TNGP10.phx.gbl. ..
"mb" <mm@hotmail.com > wrote in message
news:%2******** ********@TK2MSF TNGP10.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.Reg ularExpressions ;

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

Nov 16 '05 #4

"mb" <mm@hotmail.com > wrote in message
news:%2******** ********@tk2msf tngp13.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******** ********@TK2MSF TNGP10.phx.gbl. ..
"mb" <mm@hotmail.com > wrote in message
news:%2******** ********@TK2MSF TNGP10.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.Reg ularExpressions ;

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


Nov 16 '05 #5
mb
Is this faster than the string.Split method?
"Daniel O'Connell [C# MVP]" <onyxkirx@--NOSPAM--comcast.net> wrote in
message news:eI******** *****@TK2MSFTNG P10.phx.gbl...

"mb" <mm@hotmail.com > wrote in message
news:%2******** ********@tk2msf tngp13.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******** ********@TK2MSF TNGP10.phx.gbl. ..
"mb" <mm@hotmail.com > wrote in message
news:%2******** ********@TK2MSF TNGP10.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.Reg ularExpressions ;

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



Nov 16 '05 #6
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(str ing 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.Lengt h - 1 )
{
temp.Length = 0;
arr.Add( splitted.ToStri ng() );
founddelimiter = true;
splitted.Length = 0;
acheived = 0;
}
else
{
temp.Append(inp ut[pos]);
acheived++;
}
}
}

if ( splitted.Length > 0 )
arr.Add( splitted.ToStri ng() );

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

return (string[]) arr.ToArray(typ eof(string));

}

"mb" <mm@hotmail.com > wrote in message
news:#E******** ******@TK2MSFTN GP10.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
"mb" <mm@hotmail.com > wrote in message
news:OK******** ******@TK2MSFTN GP12.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
"mb" <mm@hotmail.com > wrote in message
news:%2******** ********@tk2msf tngp13.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.Reg ularExpressions ;
Nov 16 '05 #9
mb,
In addition to the other comments.

There are three Split functions in .NET:

Use Microsoft.Visua lBasic.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.S plit if you need to split a string based on a collection
of specific characters. Each individual character is its own delimiter.

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

Something like:
string str = "one<>two<>thre e"; string [] fields = Strings.Split(s tr, "<>", -1,
CompareMethod.B inary);
Hope this helps
Jay
"mb" <mm@hotmail.com > wrote in message
news:%2******** ********@TK2MSF TNGP10.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

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
2487
by: Carlos Ribeiro | last post by:
Hi all, While writing a small program to help other poster at c.l.py, I found a small inconsistency between the handling of keyword parameters of string.split() and the split() method of strings. I wonder if someone else had ever stumbled on it before, and if it has a good reason to work like it is. Both implementations take two...
9
4337
by: Will McGugan | last post by:
Hi, I'm curious about the behaviour of the str.split() when applied to empty strings. "".split() returns an empty list, however.. "".split("*") returns a list containing one empty string. I would have expected the second example to have also returned an empty
2
12806
by: SL_McManus | last post by:
Hi All; I am fairly new to Perl. I have a file with close to 3000 lines that I would like to split out in a certain way. I would like to put the record type starting in column 1 for 2 spaces, the employer code in column 23 for 29 spaces and employer description in column 53 for 30 spaces. I have tried modifying an existing file with no real...
6
6362
by: Senthil | last post by:
Code ---------------------- string Line = "\"A\",\"B\",\"C\",\"D\""; string Line2 = Line.Replace("\",\"","\"\",\"\""); string CSVColumns = Line2.Split("\",\"".ToCharArray());
19
10902
by: David Logan | last post by:
We need an additional function in the String class. We need the ability to suppress empty fields, so that we can more effectively parse. Right now, multiple whitespace characters create multiple empty strings in the resulting string array.
4
5770
by: Itzik | last post by:
can i split this string string str = "aa a - bb-b - ccc" with this delimiter string del = " - " i want recieve 3 items : "aa a" , "bb-b" , "ccc"
14
34908
by: Ron | last post by:
Hello, I am trying to parse a string on the newline char. I guess vbCrLf is a string constant. How can I parse my string - data - on the newline char? .... data += ASCII.GetString(buffer, 0, bytesRead) .... Dim parts() As String = data.Split(vbCrLf)
3
9651
by: Ben | last post by:
Hi I am creating a dynamic function to return a two dimensional array from a delimeted string. The delimited string is like: field1...field2...field3... field1...field2...field3... field1...field2...field3...
5
5863
by: kurt sune | last post by:
The code: Dim aLine As String = "cat" & vbNewLine & "dog" & vbNewLine & "fox" & vbNewLine Dim csvColumns1 As String() = aLine.Split(vbNewLine, vbCr, vbLf) Dim csvColumns2 As String() = Microsoft.VisualBasic.Strings.Split(aLine, vbNewLine, -1, CompareMethod.Binary)
0
7698
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
8122
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7673
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7970
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5219
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3653
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2113
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1213
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
937
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.