Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the character expression for a new line in C#?

Tags:

c#

asp.net

I've got a text box control on a page and I want people to add URLs, one on each line and then split those URLs into an array.

So, I'm trying to split them on the newline character. I've tried:

.split(Environment.Newline)
.split('vbcrlf')
.split(vbcrlf)
.split((char)Environment.Newline)

but all to no avail. What am I doing wrong?

like image 906
Piers Karsenbarg Avatar asked Dec 07 '22 00:12

Piers Karsenbarg


2 Answers

.split(new []{Environment.Newline}, StringSplitOptions.None);

This is because Environment.Newline is a string, so you must pass it in as an array of strings, as the function overload requires, also there needs to be a StringSplitOptions value included. This can either be StringSplitOption.None or StringSplitOption.RemoveEmptyEntries.

like image 191
Matt Ellen Avatar answered Jan 19 '23 09:01

Matt Ellen


"\r\n" is the string representation

\r = carriage return \n = line feed

like image 39
Brosto Avatar answered Jan 19 '23 10:01

Brosto