Solved

String.split

Posted on 2009-07-10
6
197 Views
Last Modified: 2012-05-07
How do I use the String.split method when the delimiter is a carrage return?  

Or, how do I use String.split with a string delimeter instead of a character delimiter?  So, in the case the delimiter would be  "\r"
0
Comment
Question by:dchau12
6 Comments
 
LVL 5

Accepted Solution

by:
satheeshm earned 250 total points
ID: 24827009
Hi..Try this

str2 = str1.Split('\n');
0
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 24827181
or you can use Environment.NewLine
0
 

Author Comment

by:dchau12
ID: 24827207
hey satjheeshm, str2 = str1.Split('\n');  does not work.  The delimiter is looking for a character.  A character is only one entry.  '\n' is a string.
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
LVL 18

Assisted Solution

by:Gary Davis
Gary Davis earned 250 total points
ID: 24827593
This does work. '\n' is a char not a string.

 

string str1="ss\nzz\n"; 
string[] str2 = str1.Split('\n');

Open in new window

0
 
LVL 18

Expert Comment

by:Gary Davis
ID: 24827603
Continued....
The str2 string array has three elements after the split. The last element is and empty string.
Gary Davis
0
 

Author Closing Comment

by:dchau12
ID: 31602257
I was dead wrong.  Good follow up gardavis.
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question