• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 210
  • Last Modified:


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"
2 Solutions
Hi..Try this

str2 = str1.Split('\n');
Éric MoreauSenior .Net ConsultantCommented:
or you can use Environment.NewLine
dchau12Author Commented:
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.
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Gary DavisDir Internet SvcsCommented:
This does work. '\n' is a char not a string.


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

Open in new window

Gary DavisDir Internet SvcsCommented:
The str2 string array has three elements after the split. The last element is and empty string.
Gary Davis
dchau12Author Commented:
I was dead wrong.  Good follow up gardavis.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now