.NET Framework Developer Center >
.NET Development Forums
>
Regular Expressions
>
How do you test for newline
How do you test for newline
- Hello all,
How do you put the newline character into a pattern in .Net? \n does not seem to work. Thanks in advance for any ideas and/or suggestions!
Answers
- Use "\r\n" for non-Unix systems. To make it system neutral, you can use the framework provided Environment.NewLine property in the pattern as well.
Example:
string input = "new4" + Environment.NewLine + "2line"; Console.WriteLine("Text: " + input); Console.WriteLine("Result: " + Regex.Match(input, @"\d\r\n\d").Value);
Document my code? Why do you think it's called "code"?- Marked As Answer byJialiang Ge [MSFT]MSFT, ModeratorTuesday, November 03, 2009 7:30 AM
- Hello
\r stands for carriage return (0x0D) and \n stands for line feed (0x0A). On Windows systems, text files use \r\n to terminate lines, while UNIX text files use \n.
Regards,
Jialiang Ge
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.- Marked As Answer byJialiang Ge [MSFT]MSFT, ModeratorTuesday, November 03, 2009 7:30 AM
All Replies
- Use "\r\n" for non-Unix systems. To make it system neutral, you can use the framework provided Environment.NewLine property in the pattern as well.
Example:
string input = "new4" + Environment.NewLine + "2line"; Console.WriteLine("Text: " + input); Console.WriteLine("Result: " + Regex.Match(input, @"\d\r\n\d").Value);
Document my code? Why do you think it's called "code"?- Marked As Answer byJialiang Ge [MSFT]MSFT, ModeratorTuesday, November 03, 2009 7:30 AM
- Hello
\r stands for carriage return (0x0D) and \n stands for line feed (0x0A). On Windows systems, text files use \r\n to terminate lines, while UNIX text files use \n.
Regards,
Jialiang Ge
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.- Marked As Answer byJialiang Ge [MSFT]MSFT, ModeratorTuesday, November 03, 2009 7:30 AM
- Hello
How are you? I'm writing to check the status of the issue on your side. If you have any other questions, please feel free to post here.
Regards,
Jialiang Ge
MSDN Subscriber Support in Forum
If you have any feedback of our support, please contact msdnmg@microsoft.com.
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Welcome to the All-In-One Code Framework! If you have any feedback, please tell us. - It works! Thanks a lot!
- Thanks for the help!


