convert string to html entities (for email protection)
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using Microsoft.AspNetCore.Html;
|
||||
|
||||
namespace zero.Extensions;
|
||||
|
||||
@@ -271,4 +272,21 @@ public static class StringExtensions
|
||||
yield return text.Substring(i, groupSize);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static IHtmlContent ToHtmlEntities(this string text)
|
||||
{
|
||||
StringBuilder sb = new();
|
||||
|
||||
foreach (char ch in text)
|
||||
{
|
||||
sb.Append("&#");
|
||||
sb.Append((int)ch);
|
||||
sb.Append(';');
|
||||
}
|
||||
|
||||
HtmlContentBuilder builder = new();
|
||||
builder.SetHtmlContent(sb.ToString());
|
||||
return builder;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user