Dan*_*haw 10
现在有:
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");
}
}
Run Code Online (Sandbox Code Playgroud)
修改后更仔细地遵循nl2br的php规范(感谢Max指出这一点).这仍然假设\ r \n新线虽然......
所有这些答案都是正确的,但mystring.Replace("\r?\n", "<br />");如果您的源(用户输入或数据库)可以提供,那么您应该执行一次捕获UNIX行结尾.
| 归档时间: |
|
| 查看次数: |
3256 次 |
| 最近记录: |