Is there stock standard function that does newline to <br />
encoding in ASP.Net MVC?
There is now:
public static class StockStandardFunctions
{
public static string Nl2br(this string input)
{
return input.Nl2br(true);
}
public static string Nl2br(this string input, bool is_xhtml)
{
return input.Replace("\r\n", is_xhtml ? "<br />\r\n" : "<br>\r\n");
}
}
Amended to follow the php spec for nl2br a little more closely (thanks Max for pointing that out). This still assumes \r\n new lines though...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With