473,467 Members | 1,554 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Split on multiple chars

MDB
Hello all, I have having problems figuring out how to split on a string
rather than a char. Any help would be appreciated. Here is what I am
trying to do.

string[] strMessages=sData.Split("\r\n");

I basically want to split on a new line.
Nov 15 '05 #1
5 4532
Regex.Split

Trebek
"MDB" <nospam> wrote in message
news:OJ**************@TK2MSFTNGP11.phx.gbl...
Hello all, I have having problems figuring out how to split on a string
rather than a char. Any help would be appreciated. Here is what I am
trying to do.

string[] strMessages=sData.Split("\r\n");

I basically want to split on a new line.

Nov 15 '05 #2
Unless sData is using a different EOL or doesn't have any EOLs, I believe
your code should work. I would ensure the expected EOLs are in sData. If
that doesn't help, give the StringReader class a try. It has a ReadLine
method that gives you the virtually the same functionality as your existing
code.

Scott

"MDB" <nospam> wrote in message
news:OJ**************@TK2MSFTNGP11.phx.gbl...
Hello all, I have having problems figuring out how to split on a string
rather than a char. Any help would be appreciated. Here is what I am
trying to do.

string[] strMessages=sData.Split("\r\n");

I basically want to split on a new line.

Nov 15 '05 #3
MDB
Yes it does however, something doesn't appear to be working. I actually was
in the process of converting it to use a StringReader like you suggested. I
think this will be me better results since I defiantly need to separate the
new lines.

Thanks For Your Responses.

"Scott Carter" <scott[the letter c] [ @ ] turbopower[DOTnet]> wrote in
message news:%2****************@TK2MSFTNGP11.phx.gbl...
Unless sData is using a different EOL or doesn't have any EOLs, I believe
your code should work. I would ensure the expected EOLs are in sData. If
that doesn't help, give the StringReader class a try. It has a ReadLine
method that gives you the virtually the same functionality as your existing code.

Scott

"MDB" <nospam> wrote in message
news:OJ**************@TK2MSFTNGP11.phx.gbl...
Hello all, I have having problems figuring out how to split on a string
rather than a char. Any help would be appreciated. Here is what I am
trying to do.

string[] strMessages=sData.Split("\r\n");

I basically want to split on a new line.


Nov 15 '05 #4

I think you can use the
System.Text.RegularExpressions.Regex.Split() method.
Looks like you'll have create a Regex object with your
split string, then use it to split. I haven't used it
yet, but it looks like it should work.

Hope that helps,
Ryan
-----Original Message-----
Hello all, I have having problems figuring out how to split on a stringrather than a char. Any help would be appreciated. Here is what I amtrying to do.

string[] strMessages=sData.Split("\r\n");

I basically want to split on a new line.
.

Nov 15 '05 #5
I believe this is possible also, but RegEx performance is pretty bad. I
wouldn't rule it out, but I would leave it as my last choice.

Scott

"Ryan Shahoud" <an*******@discussions.microsoft.com> wrote in message
news:0f****************************@phx.gbl...

I think you can use the
System.Text.RegularExpressions.Regex.Split() method.
Looks like you'll have create a Regex object with your
split string, then use it to split. I haven't used it
yet, but it looks like it should work.

Nov 15 '05 #6

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

Similar topics

3
by: leegold2 | last post by:
This has been done before but not sure how: Say I have a string of 1000 chars. I want to split the string into two variables (two array element variables would be OK) one has 200 chars the...
5
by: bu | last post by:
I have a database field that represents an item description and varying length. I am using the database to import the item description into another program (the other program is ODBC-aware ). The...
4
by: William Stacey [MVP] | last post by:
Would like help with a (I think) a common regex split example. Thanks for your example in advance. Cheers! Source Data Example: one "two three" four Optional, but would also like to...
19
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...
4
by: Crirus | last post by:
There is a function somewhere to split a string with multiple tokens at a time? Say I have this: aaaa#bbbbb*ccccc$dddd I whould like to split it so the result whould be aaaa bbb
14
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,...
7
by: lgbjr | last post by:
Hi All, I'm trying to split a string on every character. The string happens to be a representation of a hex number. So, my regex expression is (). Seems simple, but for some reason, I'm not...
2
by: metzger | last post by:
I am using the function listed below to handle characters events in SAX. It does not handle multiple sequential calls to this function correctly. For example, I am getting "2 4 816 32 64" as a...
3
by: Ondrej Baudys | last post by:
Hi, After trawling through the archives for a simple quote aware split implementation (ie string.split-alike that only splits outside of matching quote) and coming up short, I implemented a...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...
1
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.