{"id":43,"date":"2016-01-25T04:11:00","date_gmt":"2016-01-25T04:11:00","guid":{"rendered":"http:\/\/waynenguyen.org\/dev\/2016\/01\/25\/c-string-problems\/"},"modified":"2016-05-21T03:15:52","modified_gmt":"2016-05-21T03:15:52","slug":"c-string-problems","status":"publish","type":"post","link":"https:\/\/bruceng.com\/dev\/?p=43","title":{"rendered":"C# String problems"},"content":{"rendered":"<div dir=\"ltr\" style=\"text-align: left;\" trbidi=\"on\">\nWhen retrieving HTML or string content from some editors such as SharePoint editor, the editor may insert zero-width or control characters in the content that can cause problem methods like string.IndexOf, string.Compare, string.Replace etc.<\/p>\n<p>If the application only uses English language, it&#8217;s possible to strip all control characters from the data before doing other string operations.<\/p>\n<p>Use the Regex to do so<\/p>\n<p>data = Regex.Replace(data, @&#8221;[^x20-x7F]&#8221;, &#8220;&#8221;);<\/p>\n<p>This line will remove all characters that are not in the range 0x20 to 0x7F in the ASCII table.<\/p>\n<p>Then proceed to do string operations as per normal.<\/p><\/div>\n","protected":false},"excerpt":{"rendered":"<p>When retrieving HTML or string content from some editors such as SharePoint editor, the editor may insert zero-width or control characters in the content that can cause problem methods like string.IndexOf, string.Compare, string.Replace etc. If the application only uses English language, it&#8217;s possible to strip all control characters from the data before doing other string &hellip; <a href=\"https:\/\/bruceng.com\/dev\/?p=43\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;C# String problems&#8221;<\/span><\/a><\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[2,17,16,15],"class_list":["post-43","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-asp-net","tag-debug","tag-issues","tag-sharepoint"],"_links":{"self":[{"href":"https:\/\/bruceng.com\/dev\/index.php?rest_route=\/wp\/v2\/posts\/43","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/bruceng.com\/dev\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/bruceng.com\/dev\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/bruceng.com\/dev\/index.php?rest_route=\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/bruceng.com\/dev\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=43"}],"version-history":[{"count":1,"href":"https:\/\/bruceng.com\/dev\/index.php?rest_route=\/wp\/v2\/posts\/43\/revisions"}],"predecessor-version":[{"id":163,"href":"https:\/\/bruceng.com\/dev\/index.php?rest_route=\/wp\/v2\/posts\/43\/revisions\/163"}],"wp:attachment":[{"href":"https:\/\/bruceng.com\/dev\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=43"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/bruceng.com\/dev\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=43"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/bruceng.com\/dev\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=43"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}