{"id":84,"date":"2020-06-16T07:54:06","date_gmt":"2020-06-16T07:54:06","guid":{"rendered":"https:\/\/michaeljohnsteiner.com\/?p=84"},"modified":"2020-06-16T07:54:06","modified_gmt":"2020-06-16T07:54:06","slug":"stringhelper-cs","status":"publish","type":"post","link":"https:\/\/michaeljohnsteiner.com\/index.php\/2020\/06\/16\/stringhelper-cs\/","title":{"rendered":"StringHelper.cs"},"content":{"rendered":"\n<p>String Helper Class<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">using System;\nusing System.Collections.Generic;\nusing System.Globalization;\nusing System.IO;\nusing System.Linq;\nusing System.Net;\nusing System.Reflection;\nusing System.Security;\nusing System.Text;\nusing System.Text.RegularExpressions;\nusing System.Threading;\npublic static class StringHelper\n{\n    public static ushort[] SearchArray;\n    \/\/\/ &lt;summary>\n    \/\/\/     Included here as an example of field extraction through reflection.\n    \/\/\/     Specific knowledge of the underlying class is needed. IE. _items in the list class.\n    \/\/\/ &lt;\/summary>\n    \/\/\/ &lt;param name=\"list\">&lt;\/param>\n    \/\/\/ &lt;returns>&lt;\/returns>\n    public static byte[] ExtractArray(this List&lt;byte> list)\n    {\n        var t     = list.GetType();\n        var items = t.GetField(\"_items\", BindingFlags.NonPublic | BindingFlags.Instance);\n        return items.GetValue(list) as byte[];\n    }\n    public static string Reverse(this string str)\n    {\n        var len                                  = str.Length;\n        var Array                                = \"\";\n        for (var i = len - 1; i >= 0; --i) Array += str[i];\n        return Array;\n    }\n    public static string ToUTF16(this string str)\n    {\n        var AsciiBytes   = Encoding.ASCII.GetBytes(str);\n        var unicodeBytes = Encoding.Convert(Encoding.ASCII, Encoding.Unicode, AsciiBytes);\n        return Encoding.Unicode.GetString(unicodeBytes);\n    }\n    public static int CountInTheSet(this char c, string TheSet)\n    {\n        var Count = 0;\n        if (TheSet        == null) return Count;\n        if (TheSet.Length == 0) return Count;\n        for (var j = 0; j &lt; TheSet.Length; j++)\n            if (c == TheSet[j])\n                Count++;\n        return Count;\n    }\n    public static bool EndsWith(this string s, char value)\n    {\n        var thisLen = s.Length;\n        if (thisLen != 0)\n            if (s[thisLen - 1] == value)\n                return true;\n        return false;\n    }\n    public static void SaveToFileComma(this Dictionary&lt;string, string> d, string pathname)\n    {\n        using (var sw = new StreamWriter(pathname))\n        {\n            foreach (var e in d)\n            {\n                var k = e.Key + \",\";\n                var v = k     + e.Value;\n                sw.WriteLine(v);\n            }\n        }\n    }\n    public static IDictionary&lt;TKey, TValue> UpdateOrAdd&lt;TKey, TValue>(this IDictionary&lt;TKey, TValue> dictionary, TKey key, TValue value)\n    {\n        if (dictionary.ContainsKey(key))\n            dictionary[key] = value;\n        else\n            dictionary.Add(key, value);\n        return dictionary;\n    }\n    public static void CopyToEx&lt;T>(this List&lt;T> obj, List&lt;T> Target)\n    {\n        Target.AddRange(obj);\n    }\n    \/\/\/ &lt;summary>\n    \/\/\/     tests if c is in the set TheSet\n    \/\/\/ &lt;\/summary>\n    \/\/\/ &lt;param name=\"c\">&lt;\/param>\n    \/\/\/ &lt;param name=\"TheSet\">&lt;\/param>\n    \/\/\/ &lt;returns>&lt;\/returns>\n    public static bool InTheSet(this char c, string TheSet)\n    {\n        if (TheSet        == null) return false;\n        if (TheSet.Length == 0) return false;\n        return TheSet.Any(T => c == T);\n    }\n    public static string Join(this string separator, IEnumerable&lt;string> values)\n    {\n        using (var enumerator = values.GetEnumerator())\n        {\n            if (!enumerator.MoveNext())\n                return string.Empty;\n            var res = enumerator.Current;\n            while (enumerator.MoveNext())\n            {\n                res += separator;\n                res += enumerator.Current;\n            }\n            return res;\n        }\n    }\n    [SecuritySafeCritical]\n    [__DynamicallyInvokable]\n    private static unsafe List&lt;int> IndexesOf(this string Haystack, string Needle)\n    {\n        var Indexes = new List&lt;int>();\n        var nh      = Encoding.Default.GetBytes(Haystack);\n        var nn      = Encoding.Default.GetBytes(Needle);\n        fixed (byte* H = nh)\n        {\n            fixed (byte* N = nn)\n            {\n                var i = 0;\n                for (byte* hNext = H, hEnd = H + nh.Length; hNext &lt; hEnd; i++, hNext++)\n                {\n                    var Found = true;\n                    for (byte* hInc = hNext, nInc = N, nEnd = N + nn.Length; Found &amp;&amp; nInc &lt; nEnd; Found = *nInc == *hInc, nInc++, hInc++)\n                        ;\n                    if (Found)\n                        Indexes.Add(i);\n                }\n                return Indexes;\n            }\n        }\n    }\n    \/\/\/ &lt;summary>\n    \/\/\/     Convert a string into a byte array of type ascii\n    \/\/\/ &lt;\/summary>\n    \/\/\/ &lt;param name=\"str\">&lt;\/param>\n    \/\/\/ &lt;returns>&lt;\/returns>\n    public static byte[] StrToByteArray(this string str)\n    {\n        if (str == null)\n            return null;\n        if (str.Length == 0)\n            return null;\n        return Encoding.ASCII.GetBytes(str);\n    }\n    public static char CharAt(this string str, int Index)\n    {\n        return str.Substring(Index, 1).ToCharArray()[0];\n    }\n    \/\/\/ &lt;summary>\n    \/\/\/     Takes a delimited string and converts it into a generic object Example: 1,2,3,4 in string form = 1234 in array form\n    \/\/\/ &lt;\/summary>\n    \/\/\/ &lt;param name=\"input\">&lt;\/param>\n    \/\/\/ &lt;param name=\"separator\">&lt;\/param>\n    \/\/\/ &lt;param name=\"type\">&lt;\/param>\n    \/\/\/ &lt;returns>&lt;\/returns>\n    public static object[] StringToArray(this string input, string separator, Type type)\n    {\n        var stringList = input.Split(separator.ToCharArray(), StringSplitOptions.RemoveEmptyEntries);\n        var list       = new object[stringList.Length];\n        for (var i = 0; i &lt; stringList.Length; i++)\n            list[i] = Convert.ChangeType(stringList[i], type);\n        return list;\n    }\n    public static byte[] HexToByte(this string hex)\n    {\n        if (hex.Length % 2 == 1)\n            throw new Exception(\"The binary key cannot have an odd number of digits\");\n        var len = hex.Length >> 1;\n        var arr = new byte[len];\n        for (var i = 0; i &lt; len; ++i)\n            arr[i] = (byte) ((GetHexVal(hex[i &lt;&lt; 1]) &lt;&lt; 4) + GetHexVal(hex[(i &lt;&lt; 1) + 1]));\n        return arr;\n    }\n    private static int GetHexVal(char hex)\n    {\n        int val = hex;\n        return val - (val &lt; 58 ? 48 : val &lt; 97 ? 55 : 87);\n    }\n    \/\/\/ &lt;summary>\n    \/\/\/     takes a composite string like \"12,13,14,15,16' and creates a string array\n    \/\/\/ &lt;\/summary>\n    \/\/\/ &lt;param name=\"input\">&lt;\/param>\n    \/\/\/ &lt;param name=\"separator\">&lt;\/param>\n    \/\/\/ &lt;returns>&lt;\/returns>\n    public static string[] StringToStringArray(this string input, string separator)\n    {\n        var stringList = input.Split(separator.ToCharArray(), StringSplitOptions.RemoveEmptyEntries);\n        return stringList;\n    }\n    \/\/\/ &lt;summary>\n    \/\/\/     tests to find out if s contains all strings in TopList\n    \/\/\/ &lt;\/summary>\n    \/\/\/ &lt;param name=\"s\">&lt;\/param>\n    \/\/\/ &lt;param name=\"TopList\">&lt;\/param>\n    \/\/\/ &lt;returns>&lt;\/returns>\n    public static bool ContainsAll(this string s, List&lt;string> sl)\n    {\n        var sx  = s.ToLower();\n        var sl1 = new List&lt;string>();\n        var a   = 0;\n        foreach (var tls in sl)\n            sl1.Add(tls.ToLower());\n        var Count = 0;\n        foreach (var ts in sl1)\n            if (sx.IndexOf(ts, StringComparison.OrdinalIgnoreCase) != -1)\n                Count++;\n        if (Count > 4)\n            a = Count;\n        if (Count >= 4)\n            return true;\n        return false;\n    }\n    public static bool IsPrint(this string s)\n    {\n        var c = (byte) s[0];\n        if (c >= 0x20 &amp;&amp; c &lt;= 0x7f || c == 0x0A || c == 0x0D)\n            return true;\n        return false;\n    }\n    public static bool IsPrint(this char c)\n    {\n        if (c >= 0x20 &amp;&amp; c &lt;= 0x7f || c == 0x0A || c == 0x0D)\n            return true;\n        return false;\n    }\n    public static bool IsLetter(this char c)\n    {\n        if (c >= 65 &amp;&amp; c &lt;= 90 || c >= 97 &amp;&amp; c &lt;= 122)\n            return true;\n        return false;\n    }\n    public static bool IsAlphaNumeric(this string s)\n    {\n        return s.IsLetter() || s.IsDigit();\n    }\n    public static bool IsAlphaNumeric(this char c)\n    {\n        return c.IsLetter() || c.IsDigit();\n    }\n    public static bool IsLetter(this string s)\n    {\n        var c = (byte) s[0];\n        if (c >= 65 &amp;&amp; c &lt;= 90 || c >= 97 &amp;&amp; c &lt;= 122)\n            return true;\n        return false;\n    }\n    public static bool IsOnlyAlpha(this string s)\n    {\n        var c = 0;\n        for (var i = 0; i &lt; s.Length; i++)\n            if (IsAlpha(s))\n                c++;\n        if (c == s.Length)\n            return true;\n        return false;\n    }\n    \/\/\/ &lt;summary>\n    \/\/\/     A better IsAlpha which includes CR and LF as well as all characters between 0x20 and 0x7f\n    \/\/\/ &lt;\/summary>\n    \/\/\/ &lt;param name=\"c\">&lt;\/param>\n    \/\/\/ &lt;returns>&lt;\/returns>\n    public static bool IsAlpha(this string c)\n    {\n        var Count = 0;\n        for (var i = 0; i &lt; c.Length; i++)\n            if (IsPrint(c.Substring(0, 1)))\n                Count++;\n        if (Count == c.Length)\n            return true;\n        return false;\n    }\n    \/\/\/ &lt;summary>\n    \/\/\/     Indicates whether the specified string is null or is an empty string.\n    \/\/\/ &lt;\/summary>\n    \/\/\/ &lt;param name=\"s\">&lt;\/param>\n    \/\/\/ &lt;returns>&lt;\/returns>\n    public static bool IsNullOrEmpty(this string s)\n    {\n        return string.IsNullOrEmpty(s);\n    }\n    public static bool IsAlpha(this char c)\n    {\n        return IsPrint(c);\n    }\n    public static bool IsLowwer(this string c)\n    {\n        return c.InTheSet(\"abcdefghijklmnopqrstuvwxyz\");\n    }\n    public static bool IsLowwer(this char c)\n    {\n        return c.InTheSet(\"abcdefghijklmnopqrstuvwxyz\");\n    }\n    public static bool IsVowel(this string c)\n    {\n        return InTheSet(c.ToLower(), \"AEIOU\".ToLower());\n    }\n    public static bool IsConsonant(this string c)\n    {\n        return InTheSet(c.ToLower(), \"BCDFGHJKLMNPQRSTVWXYZ\".ToLower());\n    }\n    public static bool IsVowel(this char c)\n    {\n        return \"AEIOUaeiou\".IndexOf(c) != -1;\n    }\n    public static bool IsConsonant(this char c)\n    {\n        return \"BCDFGHJKLMNPQRSTVWXYZbcdfghjklmnpqrstvwxyz\".IndexOf(c) != -1;\n    }\n    public static int ContainsDigitAt(this string str)\n    {\n        for (var i = 0; i &lt; str.Length; i++)\n            if (IsDigit(str[i].ToString()))\n                return i;\n        return -1;\n    }\n    public static bool IsFloat(this string str)\n    {\n        return str.Any(T => T == '.');\n    }\n    public static bool IsDigit(this string c)\n    {\n        if (c.Length > 1)\n            return c.InTheSet(\"0123456789.\");\n        return c.InTheSet(\"0123456789\");\n    }\n    public static bool IsDigit(this char c)\n    {\n        return c.InTheSet(\"0123456789\");\n    }\n    public static bool IsSpecialCharacter(this string c)\n    {\n        return InTheSet(c, \"~`!@#$%^&amp;*()_+-={}[]|:;'&lt;>?,.\/\");\n    }\n    public static bool IsSpecialCharacter(this char c)\n    {\n        return InTheSet(c, \"~`!@#$%^&amp;*()_+-={}[]|:;'&lt;>?,.\/\");\n    }\n    \/\/\/ &lt;summary>\n    \/\/\/     Test c to see if it contains any special characters\n    \/\/\/ &lt;\/summary>\n    \/\/\/ &lt;param name=\"c\">&lt;\/param>\n    \/\/\/ &lt;returns>&lt;\/returns>\n    public static bool ContainsSpecialCharacter(this string c)\n    {\n        var TheSet = \"~`!@#$%^&amp;*()_+-={}[]|:;'&lt;>?,.\/\";\n        for (var j = 0; j &lt; TheSet.Length; j++)\n        for (var k = 0; k &lt; c.Length; k++)\n            if (c[k] == TheSet[j])\n                return true;\n        return false;\n    }\n    \/\/\/ &lt;summary>\n    \/\/\/     Check to see if this character is contained within the set\n    \/\/\/ &lt;\/summary>\n    \/\/\/ &lt;param name=\"c\">The c.&lt;\/param>\n    \/\/\/ &lt;param name=\"TheSet\">The set.&lt;\/param>\n    \/\/\/ &lt;returns>&lt;\/returns>\n    public static bool InTheSet(this string c, string TheSet)\n    {\n        var result = false;\n        if (TheSet == null)\n            return result;\n        if (TheSet.Length == 0)\n            return result;\n        if (c == null)\n            return result;\n        if (c.Length == 0)\n            return result;\n        for (var j = 0; j &lt; TheSet.Length; j++)\n            if (c[0] == TheSet[j])\n            {\n                result = true;\n                break;\n            }\n        return result;\n    }\n    \/\/\/ &lt;summary>\n    \/\/\/     Check to see if this character is contained within the set\n    \/\/\/ &lt;\/summary>\n    \/\/\/ &lt;param name=\"c\">The c.&lt;\/param>\n    \/\/\/ &lt;param name=\"TheSet\">The set.&lt;\/param>\n    \/\/\/ &lt;returns>&lt;\/returns>\n    public static bool InTheSet(this char c, char[] TheSet)\n    {\n        var result = false;\n        if (TheSet == null)\n            return result;\n        if (TheSet.Length == 0)\n            return result;\n        for (var j = 0; j &lt; TheSet.Length; j++)\n            if (c == TheSet[j])\n            {\n                result = true;\n                break;\n            }\n        return result;\n    }\n    public static int IndexOfN(this string str, string pattern, int n)\n    {\n        var c  = 0;\n        var f  = pattern[0];\n        var pl = pattern.Length;\n        var e  = str.IndexOf(f);\n        if (e == -1)\n            return -1;\n        do\n        {\n            try\n            {\n                e = str.IndexOf(pattern, e, StringComparison.OrdinalIgnoreCase);\n            }\n            catch\n            {\n                return -1;\n            }\n            if (e == -1)\n                return -1;\n            c++;\n            e = str.IndexOf(f, e + pl + 1);\n            if (e == -1)\n                return -1;\n        } while (c &lt; n);\n        return e - 1;\n    }\n    \/\/\/ &lt;summary>\n    \/\/\/     Gets all indices of the pattern within the string\n    \/\/\/ &lt;\/summary>\n    \/\/\/ &lt;param name=\"str\">The string.&lt;\/param>\n    \/\/\/ &lt;param name=\"pattern\">The pattern.&lt;\/param>\n    \/\/\/ &lt;returns>&lt;\/returns>\n    public static List&lt;int> GetAllIndices(this string str, string pattern)\n    {\n        var lst = new List&lt;int>();\n        var f   = pattern[0];\n        var pl  = pattern.Length;\n        var e   = 0;\n        var p   = str.IndexOf(f);\n        do\n        {\n            try\n            {\n                e = str.IndexOf(pattern, p, StringComparison.OrdinalIgnoreCase);\n            }\n            catch\n            {\n                return lst;\n            }\n            if (e != -1)\n            {\n                lst.Add(e);\n                p = str.IndexOf(f, e + pl);\n                if (p == -1)\n                    break;\n            }\n            else\n            {\n                break;\n            }\n        } while (e != -1);\n        return lst;\n    }\n    public static int GetCharacterCount(this string p)\n    {\n        var map = new Dictionary&lt;char, int>();\n        foreach (var c in p)\n            if (!map.ContainsKey(c))\n                map.Add(c, 1);\n            else\n                map[c] += 1;\n        return map.Count;\n    }\n    public static Dictionary&lt;char, int> CountCharacter(this string p)\n    {\n        var map = new Dictionary&lt;char, int>();\n        foreach (var c in p)\n            if (!map.ContainsKey(c))\n                map.Add(c, 1);\n            else\n                map[c] += 1;\n        return map;\n    }\n    public static int CharacterCount(this string p, char c0)\n    {\n        var count = 0;\n        foreach (var c in p)\n            if (c.Equals(c0))\n                count++;\n        return count;\n    }\n    public static bool MajorCharacter(this string p, char c)\n    {\n        var cc = p.CountCharacter();\n        var hc = '\\0';\n        var mv = 0;\n        foreach (var v in cc)\n            if (v.Value > mv)\n            {\n                mv = v.Value;\n                hc = v.Key;\n            }\n        return hc == c;\n    }\n    \/\/\/ &lt;summary>\n    \/\/\/     Test to see if p contains only characters contained in s\n    \/\/\/ &lt;\/summary>\n    public static bool ContainsOnly(this string p, string s)\n    {\n        return p.Count(c => s.Any(c1 => c == c1)) == p.Length;\n    }\n    public static bool ContainsOnlyTheseCharacters(this string p, params char[] c)\n    {\n        var cc = p.CountCharacter();\n        if (cc.Count > c.Length)\n            return false;\n        var pac = p.ToCharArray();\n        var u   = pac.Except(c).ToArray();\n        if (u.Length == 0)\n            return true;\n        return false;\n    }\n    public static double Uniqueness(this string s, double CharactersAllowed)\n    {\n        var map = new Dictionary&lt;char, int>();\n        foreach (var c in s)\n            if (!map.ContainsKey(c))\n                map.Add(c, 1);\n            else\n                map[c] += 1;\n        return map.Count \/ CharactersAllowed * 100D;\n    }\n    \/\/\/ &lt;summary>\n    \/\/\/     find the nth occurrence of substr within str return the index (For reverse compatibility)\n    \/\/\/ &lt;\/summary>\n    \/\/\/ &lt;param name=\"str\">&lt;\/param>\n    \/\/\/ &lt;param name=\"substr\">&lt;\/param>\n    \/\/\/ &lt;param name=\"nth\">&lt;\/param>\n    \/\/\/ &lt;returns>&lt;\/returns>\n    public static int SuperIndexOf(this string str, string substr, int nth)\n    {\n        var e = 0;\n        var c = 0;\n        var l = str.Length;\n        do\n        {\n            e = str.IndexOf(substr, e, StringComparison.CurrentCultureIgnoreCase);\n            if (e == -1)\n                return -1;\n            c++;\n            e++;\n            if (e >= l)\n                return -1;\n        } while (c &lt; nth);\n        return e - 1;\n    }\n    \/\/\/ &lt;summary>\n    \/\/\/     find the nth occurrence of substr within str return the index (IgnoreCase)\n    \/\/\/ &lt;\/summary>\n    public static int IndexNOf(this string str, string substr, int nth)\n    {\n        if (str == null || substr == null || nth &lt; 0)\n            return -1;\n        var e = 0;\n        var c = 0;\n        var l = str.Length;\n        do\n        {\n            e = str.IndexOf(substr, e, StringComparison.CurrentCultureIgnoreCase);\n            if (e == -1)\n                return -1;\n            c++;\n            e++;\n            if (e >= l)\n                return -1;\n        } while (c &lt; nth);\n        return e - 1;\n    }\n    public static List&lt;string> StringToList(this string input, string separator)\n    {\n        return input.Split(separator.ToCharArray(), StringSplitOptions.RemoveEmptyEntries).ToList();\n    }\n    \/\/\/ &lt;summary>\n    \/\/\/     Returns a &lt;see cref=\"System.String\" \/> that represents this instance with commas.\n    \/\/\/ &lt;\/summary>\n    \/\/\/ &lt;param name=\"s\">The s.&lt;\/param>\n    \/\/\/ &lt;returns>\n    \/\/\/     A &lt;see cref=\"System.String\" \/> that represents this instance.\n    \/\/\/ &lt;\/returns>\n    public static string ToStringWithCommas(this int s)\n    {\n        return s.ToString(\"N0\");\n    }\n    public static string InsertCommas(this string str)\n    {\n        if (str == null)\n            return \"\";\n        var pos  = str.IndexOf('.');\n        var frac = \"\";\n        if (pos != -1)\n        {\n            frac = str.Substring(pos);\n            str  = str.Substring(0, pos);\n        }\n        var rs  = str;\n        var len = str.Length;\n        if (len > 3)\n            for (int i = 0, j = 0; i &lt; len; i++)\n                if (i != 0)\n                    if ((len - i) % 3 == 0)\n                    {\n                        rs = rs.Insert(i + j, \",\");\n                        j++;\n                    }\n        return rs + frac;\n    }\n    public static byte[] ToByteArrayDefault(this string str)\n    {\n        return Encoding.Default.GetBytes(str);\n    }\n    public static byte[] FromBase64(this string str)\n    {\n        return Convert.FromBase64String(str);\n    }\n    public static string B64Encode(this string S)\n    {\n        if (S == null)\n            return \"\";\n        var encbuff = Encoding.Default.GetBytes(S);\n        var enc     = Convert.ToBase64String(encbuff);\n        return enc;\n    }\n    public static int WordCount(this string s)\n    {\n        var Count = 0;\n        foreach (var sc in s)\n            if (sc == ' ')\n                Count++;\n        return Count + 1;\n    }\n    \/\/\/ &lt;summary>\n    \/\/\/     Allocate and zero the search array\n    \/\/\/ &lt;\/summary>\n    \/\/\/ &lt;param name=\"s\">&lt;\/param>\n    public static void NewSearchArray(this string s)\n    {\n        SearchArray = new ushort[s.Length];\n    }\n    \/\/\/ &lt;summary>\n    \/\/\/     Get the search array for external use\n    \/\/\/ &lt;\/summary>\n    \/\/\/ &lt;param name=\"s\">&lt;\/param>\n    \/\/\/ &lt;returns>&lt;\/returns>\n    public static ushort[] GetSearchArray(this string s)\n    {\n        return SearchArray;\n    }\n    public static bool IsEven(this short o)\n    {\n        if ((ulong) o % 2 == 0)\n            return true;\n        return false;\n    }\n    public static bool IsEven(this ushort o)\n    {\n        if ((ulong) o % 2 == 0)\n            return true;\n        return false;\n    }\n    public static bool IsEven(this uint o)\n    {\n        if ((ulong) o % 2 == 0)\n            return true;\n        return false;\n    }\n    public static bool IsEven(this ulong o)\n    {\n        if (o % 2 == 0)\n            return true;\n        return false;\n    }\n    public static string RemoveDiacritics(this string s)\n    {\n        var stFormD = s.Normalize(NormalizationForm.FormD);\n        var sb      = new StringBuilder();\n        for (var i = 0; i &lt; stFormD.Length; i++)\n        {\n            var uc = CharUnicodeInfo.GetUnicodeCategory(stFormD[i]);\n            if (uc != UnicodeCategory.NonSpacingMark)\n                sb.Append(stFormD[i]);\n        }\n        return sb.ToString().Normalize(NormalizationForm.FormC);\n    }\n    public static string RemoveSpaces(this string s)\n    {\n        return s.Replace(\" \", \"\");\n    }\n    public static bool IsNumber(this string s, bool floatpoint)\n    {\n        int    i;\n        double d;\n        var    withoutWhiteSpace = s.RemoveSpaces();\n        if (floatpoint)\n            return double.TryParse(withoutWhiteSpace, NumberStyles.Any, Thread.CurrentThread.CurrentUICulture, out d);\n        return int.TryParse(withoutWhiteSpace, out i);\n    }\n    public static string UppercaseFirstLetter(this string value)\n    {\n        if (value.Length > 0)\n        {\n            var array = value.ToCharArray();\n            array[0] = char.ToUpper(array[0]);\n            return new string(array);\n        }\n        return value;\n    }\n    public static string ToInitials(this string str)\n    {\n        return Regex.Replace(str, @\"^(?'b'\\w)\\w*,\\s*(?'a'\\w)\\w*$|^(?'a'\\w)\\w*\\s*(?'b'\\w)\\w*$\", \"${a}${b}\", RegexOptions.Singleline);\n    }\n    public static string RemoveLineBreaks(this string lines)\n    {\n        return lines.Replace(\"\\r\", \"\").Replace(\"\\n\", \"\");\n    }\n    public static string ReplaceLineBreaks(this string lines, string replacement)\n    {\n        return lines.Replace(\"\\r\\n\", replacement).Replace(\"\\r\", replacement).Replace(\"\\n\", replacement);\n    }\n    public static string StripHtml(this string html)\n    {\n        if (string.IsNullOrEmpty(html))\n            return string.Empty;\n        return Regex.Replace(html, @\"&lt;[^>]*>\", \" \");\n    }\n    public static string StripHTML(this string source)\n    {\n        try\n        {\n            string result;\n            result = source.Replace(\"\\r\", \" \");\n            result = result.Replace(\"\\n\", \" \");\n            result = result.Replace(\"\\t\", string.Empty);\n            result = Regex.Replace(result, @\"( )+\",                      \" \");\n            result = Regex.Replace(result, @\"&lt;( )*head([^>])*>\",         \"&lt;head>\",     RegexOptions.IgnoreCase);\n            result = Regex.Replace(result, @\"(&lt;( )*(\/)( )*head( )*>)\",   \"&lt;\/head>\",    RegexOptions.IgnoreCase);\n            result = Regex.Replace(result, \"(&lt;head>).*?(&lt;\/head>)\",       string.Empty, RegexOptions.IgnoreCase);\n            result = Regex.Replace(result, @\"&lt;( )*script([^>])*>\",       \"&lt;script>\",   RegexOptions.IgnoreCase);\n            result = Regex.Replace(result, @\"(&lt;( )*(\/)( )*script( )*>)\", \"&lt;\/script>\",  RegexOptions.IgnoreCase);\n            result = Regex.Replace(result, @\"(&lt;script>).*?(&lt;\/script>)\",  string.Empty, RegexOptions.IgnoreCase);\n            result = Regex.Replace(result, @\"&lt;( )*style([^>])*>\",        \"&lt;style>\",    RegexOptions.IgnoreCase);\n            result = Regex.Replace(result, @\"(&lt;( )*(\/)( )*style( )*>)\",  \"&lt;\/style>\",   RegexOptions.IgnoreCase);\n            result = Regex.Replace(result, \"(&lt;style>).*?(&lt;\/style>)\",     string.Empty, RegexOptions.IgnoreCase);\n            result = Regex.Replace(result, @\"&lt;( )*td([^>])*>\",           \"\\t\",         RegexOptions.IgnoreCase);\n            result = Regex.Replace(result, @\"&lt;( )*br( )*(\/)?( )*>\",      \"\\r\",         RegexOptions.IgnoreCase);\n            result = Regex.Replace(result, @\"&lt;( )*li( )*>\",              \"\\r\",         RegexOptions.IgnoreCase);\n            result = Regex.Replace(result, @\"&lt;( )*div([^>])*>\",          \"\\r\\r\",       RegexOptions.IgnoreCase);\n            result = Regex.Replace(result, @\"&lt;( )*tr([^>])*>\",           \"\\r\\r\",       RegexOptions.IgnoreCase);\n            result = Regex.Replace(result, @\"&lt;( )*p([^>])*>\",            \"\\r\\r\",       RegexOptions.IgnoreCase);\n            result = Regex.Replace(result, @\"&lt;[^>]*>\",                   string.Empty, RegexOptions.IgnoreCase);\n            result = Regex.Replace(result, @\" \",                         \" \",          RegexOptions.IgnoreCase);\n            result = Regex.Replace(result, @\"&bull;\",                    \" * \",        RegexOptions.IgnoreCase);\n            result = Regex.Replace(result, @\"&lsaquo;\",                  \"&lt;\",          RegexOptions.IgnoreCase);\n            result = Regex.Replace(result, @\"&rsaquo;\",                  \">\",          RegexOptions.IgnoreCase);\n            result = Regex.Replace(result, @\"&trade;\",                   \"(tm)\",       RegexOptions.IgnoreCase);\n            result = Regex.Replace(result, @\"&frasl;\",                   \"\/\",          RegexOptions.IgnoreCase);\n            result = Regex.Replace(result, @\"&lt;\",                      \"&lt;\",          RegexOptions.IgnoreCase);\n            result = Regex.Replace(result, @\"&gt;\",                      \">\",          RegexOptions.IgnoreCase);\n            result = Regex.Replace(result, @\"&copy;\",                    \"(c)\",        RegexOptions.IgnoreCase);\n            result = Regex.Replace(result, @\"&reg;\",                     \"(r)\",        RegexOptions.IgnoreCase);\n            result = Regex.Replace(result, @\"&amp;(.{2,6});\",                string.Empty, RegexOptions.IgnoreCase);\n            result = result.Replace(\"\\n\", \"\\r\");\n            result = Regex.Replace(result, \"(\\r)( )+(\\r)\",  \"\\r\\r\", RegexOptions.IgnoreCase);\n            result = Regex.Replace(result, \"(\\t)( )+(\\t)\",  \"\\t\\t\", RegexOptions.IgnoreCase);\n            result = Regex.Replace(result, \"(\\t)( )+(\\r)\",  \"\\t\\r\", RegexOptions.IgnoreCase);\n            result = Regex.Replace(result, \"(\\r)( )+(\\t)\",  \"\\r\\t\", RegexOptions.IgnoreCase);\n            result = Regex.Replace(result, \"(\\r)(\\t)+(\\r)\", \"\\r\\r\", RegexOptions.IgnoreCase);\n            result = Regex.Replace(result, \"(\\r)(\\t)+\",     \"\\r\\t\", RegexOptions.IgnoreCase);\n            var breaks = \"\\r\\r\\r\";\n            var tabs   = \"\\t\\t\\t\\t\\t\";\n            for (var index = 0; index &lt; result.Length; index++)\n            {\n                result = result.Replace(breaks, \"\\r\\r\");\n                result = result.Replace(tabs,   \"\\t\\t\\t\\t\");\n                breaks = breaks + \"\\r\";\n                tabs   = tabs   + \"\\t\";\n            }\n            return result;\n        }\n        catch\n        {\n            return source;\n        }\n    }\n    public static string StripHTMLNE(this string source)\n    {\n        try\n        {\n            string result;\n            result = source.Replace(\"\\r\", \" \");\n            result = result.Replace(\"\\n\", \" \");\n            result = result.Replace(\"\\t\", \" \");\n            result = Regex.Replace(result, @\"( )+\",                      \" \",         RegexOptions.IgnoreCase);\n            result = Regex.Replace(result, @\"&lt;( )*head([^>])*>\",         \"&lt;head>\",    RegexOptions.IgnoreCase);\n            result = Regex.Replace(result, @\"(&lt;( )*(\/)( )*head( )*>)\",   \"&lt;\/head>\",   RegexOptions.IgnoreCase);\n            result = Regex.Replace(result, \"(&lt;head>).*?(&lt;\/head>)\",       \" \",         RegexOptions.IgnoreCase);\n            result = Regex.Replace(result, @\"&lt;( )*script([^>])*>\",       \"&lt;script>\",  RegexOptions.IgnoreCase);\n            result = Regex.Replace(result, @\"(&lt;( )*(\/)( )*script( )*>)\", \"&lt;\/script>\", RegexOptions.IgnoreCase);\n            result = Regex.Replace(result, @\"(&lt;script>).*?(&lt;\/script>)\",  \" \",         RegexOptions.IgnoreCase);\n            result = Regex.Replace(result, @\"&lt;( )*style([^>])*>\",        \"&lt;style>\",   RegexOptions.IgnoreCase);\n            result = Regex.Replace(result, @\"(&lt;( )*(\/)( )*style( )*>)\",  \"&lt;\/style>\",  RegexOptions.IgnoreCase);\n            result = Regex.Replace(result, \"(&lt;style>).*?(&lt;\/style>)\",     \" \",         RegexOptions.IgnoreCase);\n            result = Regex.Replace(result, @\"&lt;( )*td([^>])*>\",           \"\\t\",        RegexOptions.IgnoreCase);\n            result = Regex.Replace(result, @\"&lt;( )*br( )*(\/)?( )*>\",      \"\\r\",        RegexOptions.IgnoreCase);\n            result = Regex.Replace(result, @\"&lt;( )*li( )*>\",              \"\\r\",        RegexOptions.IgnoreCase);\n            result = Regex.Replace(result, @\"&lt;( )*div([^>])*>\",          \"\\r\\r\",      RegexOptions.IgnoreCase);\n            result = Regex.Replace(result, @\"&lt;( )*tr([^>])*>\",           \"\\r\\r\",      RegexOptions.IgnoreCase);\n            result = Regex.Replace(result, @\"&lt;( )*p([^>])*>\",            \"\\r\\r\",      RegexOptions.IgnoreCase);\n            result = Regex.Replace(result, @\"&lt;[^>]*>\",                   \" \",         RegexOptions.IgnoreCase);\n            result = Regex.Replace(result, @\" \",                         \" \",         RegexOptions.IgnoreCase);\n            result = Regex.Replace(result, @\"&amp;nbsp\",                     \" \",         RegexOptions.IgnoreCase);\n            result = Regex.Replace(result, @\"&bull;\",                    \" * \",       RegexOptions.IgnoreCase);\n            result = Regex.Replace(result, @\"&lsaquo;\",                  \"&lt;\",         RegexOptions.IgnoreCase);\n            result = Regex.Replace(result, @\"&rsaquo;\",                  \">\",         RegexOptions.IgnoreCase);\n            result = Regex.Replace(result, @\"&trade;\",                   \"(tm)\",      RegexOptions.IgnoreCase);\n            result = Regex.Replace(result, @\"&frasl;\",                   \"\/\",         RegexOptions.IgnoreCase);\n            result = Regex.Replace(result, @\"&lt;\",                      \"&lt;\",         RegexOptions.IgnoreCase);\n            result = Regex.Replace(result, @\"&gt;\",                      \">\",         RegexOptions.IgnoreCase);\n            result = Regex.Replace(result, @\"&copy;\",                    \"(c)\",       RegexOptions.IgnoreCase);\n            result = Regex.Replace(result, @\"&reg;\",                     \"(r)\",       RegexOptions.IgnoreCase);\n            result = Regex.Replace(result, @\"&amp;(.{2,6});\",                \" \",         RegexOptions.IgnoreCase);\n            result = result.Replace(\"\\n\", \"\\r\");\n            result = Regex.Replace(result, \"(\\r)( )+(\\r)\",  \"\\r\\r\", RegexOptions.IgnoreCase);\n            result = Regex.Replace(result, \"(\\t)( )+(\\t)\",  \"\\t\\t\", RegexOptions.IgnoreCase);\n            result = Regex.Replace(result, \"(\\t)( )+(\\r)\",  \"\\t\\r\", RegexOptions.IgnoreCase);\n            result = Regex.Replace(result, \"(\\r)( )+(\\t)\",  \"\\r\\t\", RegexOptions.IgnoreCase);\n            result = Regex.Replace(result, \"(\\r)(\\t)+(\\r)\", \"\\r\\r\", RegexOptions.IgnoreCase);\n            result = Regex.Replace(result, \"(\\r)(\\t)+\",     \"\\r\\t\", RegexOptions.IgnoreCase);\n            var breaks = \"\\r\\r\\r\";\n            var tabs   = \"\\t\\t\\t\\t\\t\";\n            for (var index = 0; index &lt; result.Length; index++)\n            {\n                result = result.Replace(breaks, \"\\r\\r\");\n                result = result.Replace(tabs,   \"\\t\\t\\t\\t\");\n                breaks = breaks + \"\\r\";\n                tabs   = tabs   + \"\\t\";\n            }\n            return result;\n        }\n        catch\n        {\n            return source;\n        }\n    }\n    public static string StripHTMLAll(this string source)\n    {\n        try\n        {\n            string result;\n            result = source.Replace(\"\\r\", \" \");\n            result = result.Replace(\"\\n\", \" \");\n            result = result.Replace(\"\\t\", \" \");\n            result = Regex.Replace(result, @\"( )+\",                      \" \",         RegexOptions.IgnoreCase);\n            result = Regex.Replace(result, @\"&lt;( )*head([^>])*>\",         \"&lt;head>\",    RegexOptions.IgnoreCase);\n            result = Regex.Replace(result, @\"(&lt;( )*(\/)( )*head( )*>)\",   \"&lt;\/head>\",   RegexOptions.IgnoreCase);\n            result = Regex.Replace(result, \"(&lt;head>).*?(&lt;\/head>)\",       \" \",         RegexOptions.IgnoreCase);\n            result = Regex.Replace(result, @\"&lt;( )*script([^>])*>\",       \"&lt;script>\",  RegexOptions.IgnoreCase);\n            result = Regex.Replace(result, @\"(&lt;( )*(\/)( )*script( )*>)\", \"&lt;\/script>\", RegexOptions.IgnoreCase);\n            result = Regex.Replace(result, @\"(&lt;script>).*?(&lt;\/script>)\",  \" \",         RegexOptions.IgnoreCase);\n            result = Regex.Replace(result, @\"&lt;( )*style([^>])*>\",        \"&lt;style>\",   RegexOptions.IgnoreCase);\n            result = Regex.Replace(result, @\"(&lt;( )*(\/)( )*style( )*>)\",  \"&lt;\/style>\",  RegexOptions.IgnoreCase);\n            result = Regex.Replace(result, \"(&lt;style>).*?(&lt;\/style>)\",     \" \",         RegexOptions.IgnoreCase);\n            result = Regex.Replace(result, @\"&lt;( )*td([^>])*>\",           \"\\t\",        RegexOptions.IgnoreCase);\n            result = Regex.Replace(result, @\"&lt;( )*br( )*(\/)?( )*>\",      \"\\r\",        RegexOptions.IgnoreCase);\n            result = Regex.Replace(result, @\"&lt;( )*li( )*>\",              \"\\r\",        RegexOptions.IgnoreCase);\n            result = Regex.Replace(result, @\"&lt;( )*div([^>])*>\",          \"\\r\\r\",      RegexOptions.IgnoreCase);\n            result = Regex.Replace(result, @\"&lt;( )*tr([^>])*>\",           \"\\r\\r\",      RegexOptions.IgnoreCase);\n            result = Regex.Replace(result, @\"&lt;( )*p([^>])*>\",            \"\\r\\r\",      RegexOptions.IgnoreCase);\n            result = Regex.Replace(result, @\"&lt;[^>]*>\",                   \" \",         RegexOptions.IgnoreCase);\n            result = Regex.Replace(result, @\" \",                         \" \",         RegexOptions.IgnoreCase);\n            result = Regex.Replace(result, @\"&amp;nbsp\",                     \" \",         RegexOptions.IgnoreCase);\n            result = Regex.Replace(result, @\"&bull;\",                    \" * \",       RegexOptions.IgnoreCase);\n            result = Regex.Replace(result, @\"&lsaquo;\",                  \"&lt;\",         RegexOptions.IgnoreCase);\n            result = Regex.Replace(result, @\"&rsaquo;\",                  \">\",         RegexOptions.IgnoreCase);\n            result = Regex.Replace(result, @\"&trade;\",                   \"(tm)\",      RegexOptions.IgnoreCase);\n            result = Regex.Replace(result, @\"&frasl;\",                   \"\/\",         RegexOptions.IgnoreCase);\n            result = Regex.Replace(result, @\"&lt;\",                      \"&lt;\",         RegexOptions.IgnoreCase);\n            result = Regex.Replace(result, @\"&gt;\",                      \">\",         RegexOptions.IgnoreCase);\n            result = Regex.Replace(result, @\"&copy;\",                    \"(c)\",       RegexOptions.IgnoreCase);\n            result = Regex.Replace(result, @\"&reg;\",                     \"(r)\",       RegexOptions.IgnoreCase);\n            result = Regex.Replace(result, @\"&amp;(.{2,6});\",                \" \",         RegexOptions.IgnoreCase);\n            result = result.Replace(\"\\n\", \" \");\n            result = result.Replace(\"\\r\", \" \");\n            result = result.Replace(\"\\t\", \" \");\n            result = result.Replace(\"\\n\", \"\\r\");\n            result = Regex.Replace(result, \"(\\r)( )+(\\r)\",  \"\\r\\r\", RegexOptions.IgnoreCase);\n            result = Regex.Replace(result, \"(\\t)( )+(\\t)\",  \"\\t\\t\", RegexOptions.IgnoreCase);\n            result = Regex.Replace(result, \"(\\t)( )+(\\r)\",  \"\\t\\r\", RegexOptions.IgnoreCase);\n            result = Regex.Replace(result, \"(\\r)( )+(\\t)\",  \"\\r\\t\", RegexOptions.IgnoreCase);\n            result = Regex.Replace(result, \"(\\r)(\\t)+(\\r)\", \"\\r\\r\", RegexOptions.IgnoreCase);\n            result = Regex.Replace(result, \"(\\r)(\\t)+\",     \"\\r\\t\", RegexOptions.IgnoreCase);\n            var breaks = \"\\r\\r\\r\";\n            var tabs   = \"\\t\\t\\t\\t\\t\";\n            for (var index = 0; index &lt; result.Length; index++)\n            {\n                result = result.Replace(breaks, \"\\r\\r\");\n                result = result.Replace(tabs,   \"\\t\\t\\t\\t\");\n                breaks = breaks + \"\\r\";\n                tabs   = tabs   + \"\\t\";\n            }\n            return result;\n        }\n        catch\n        {\n            return source;\n        }\n    }\n    \/\/\/ &lt;summary>\n    \/\/\/     If the searchstring contains any occurrences of the list values returns true else false.\n    \/\/\/ &lt;\/summary>\n    public static bool ContainsAny(this string searchstring, params string[] list)\n    {\n        var sslcs = searchstring.ToLower();\n        var bfss  = sslcs.GetBytes(Encoding.ASCII);\n        foreach (var s in list)\n        {\n            var lcs = s.ToLower();\n            var bf  = lcs.GetBytes(Encoding.ASCII);\n            var bm  = new BoyerMoore(bf);\n            if (bm.Search(bfss) != -1)\n                return true;\n        }\n        return false;\n    }\n    public static string DownloadURLToString(this string url)\n    {\n        var webReq = (HttpWebRequest) WebRequest.Create(url);\n        try\n        {\n            webReq.CookieContainer = new CookieContainer();\n            webReq.Method          = \"GET\";\n            webReq.UserAgent       = \"Mozilla\/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/80.0.3987.132 Safari\/537.36\";\n            using (var response = webReq.GetResponse())\n            {\n                using (var stream = response.GetResponseStream())\n                {\n                    var reader = new StreamReader(stream);\n                    return reader.ReadToEnd();\n                }\n            }\n        }\n        catch (Exception ex)\n        {\n        }\n        return \"\";\n    }\n    public static string ReverseWords(this string str, char sep)\n    {\n        char temp;\n        int  left  = 0, middle = 0;\n        var  chars = str.ToCharArray();\n        Array.Reverse(chars);\n        for (var i = 0; i &lt;= chars.Length; i++)\n        {\n            if (i != chars.Length &amp;&amp; chars[i] != sep)\n                continue;\n            if (left == i || left + 1 == i)\n            {\n                left = i + 1;\n                continue;\n            }\n            middle = (i - left - 1) \/ 2 + left;\n            for (var j = i - 1; j > middle; j--, left++)\n            {\n                temp        = chars[left];\n                chars[left] = chars[j];\n                chars[j]    = temp;\n            }\n            left = i + 1;\n        }\n        return new string(chars);\n    }\n    public static string ReverseWords(this string str)\n    {\n        return str.ReverseWords(' ');\n    }\n}<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>String Helper Class<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[2],"tags":[29,28,27],"_links":{"self":[{"href":"https:\/\/michaeljohnsteiner.com\/index.php\/wp-json\/wp\/v2\/posts\/84"}],"collection":[{"href":"https:\/\/michaeljohnsteiner.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/michaeljohnsteiner.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/michaeljohnsteiner.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/michaeljohnsteiner.com\/index.php\/wp-json\/wp\/v2\/comments?post=84"}],"version-history":[{"count":1,"href":"https:\/\/michaeljohnsteiner.com\/index.php\/wp-json\/wp\/v2\/posts\/84\/revisions"}],"predecessor-version":[{"id":85,"href":"https:\/\/michaeljohnsteiner.com\/index.php\/wp-json\/wp\/v2\/posts\/84\/revisions\/85"}],"wp:attachment":[{"href":"https:\/\/michaeljohnsteiner.com\/index.php\/wp-json\/wp\/v2\/media?parent=84"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/michaeljohnsteiner.com\/index.php\/wp-json\/wp\/v2\/categories?post=84"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/michaeljohnsteiner.com\/index.php\/wp-json\/wp\/v2\/tags?post=84"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}