Solved

String.split

Posted on 2009-07-10
6
200 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
MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

 
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

MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

Question has a verified solution.

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

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

679 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