153
1
using System; using System.Text.RegularExpressions; using System.Net;
2
using System.Web; using System.Text;
3
4
public static class Program
5
{
6
//Tue 20-Aug-19 6:53pm Markus - http://metadataconsulting.blogspot.com/2019/08/Remove-all-ANSI-Control-Characters-fast-in-C-Sharp.html
7
public static string RemoveUnicodeControlChars(this string s) {
8
9
StringBuilder sb = new StringBuilder(s.Length);
10
for (int i = 0; i < s.Length; i++)
11
if ( !Char.IsControl(s[i]) )
12
sb.Append(s[i]);
13
14
return sb.ToString();
15
}
16
17
public static string URLExpander(this string URL) {
18
19
//removal ASCII and UNICODE control characters, if they exist
20
//string urlText = Regex.Replace(URL, @"[\u0000-\u0008|\u000B-\u000C|\u000E-\u001F|\u0080-\u009F]", "");
21
string urlText = URL.RemoveUnicodeControlChars();
22
23
if (string.IsNullOrWhiteSpace(urlText))
24
return string.Empty;
Cached Result