Solved

String.split

Posted on 2009-07-10
6
195 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 69

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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
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.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

746 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now