Split on multiple chars

  • Thread starter Thread starter MDB
  • Start date Start date
M

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.
 
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
 
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 said:
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 said:
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.
 
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
 
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
 
Back
Top