{"id":226,"date":"2011-05-19T23:44:27","date_gmt":"2011-05-20T05:44:27","guid":{"rendered":"http:\/\/www.bdragon.com\/lair\/?p=226"},"modified":"2011-05-20T00:33:24","modified_gmt":"2011-05-20T06:33:24","slug":"remove-byte-order-mark-bom-in-classic-asp-vbscript","status":"publish","type":"post","link":"https:\/\/bdragon.com\/lair\/2011\/05\/remove-byte-order-mark-bom-in-classic-asp-vbscript\/","title":{"rendered":"Remove Byte-Order Mark (BOM) In Classic ASP, VBScript"},"content":{"rendered":"<div class=\"entry\">\n<p>I wasn&#8217;t able to find much on this with web searching (enough to be able to cobble together this solution, but that&#8217;s it!)&#8230; so thought I&#8217;d post it in case it helps others.\u00a0 I needed to remove the &#8220;byte order mark&#8221; (BOM) from the beginning of a file that had been read into a variable in a classic asp page (VBscript).\u00a0 The BOM was output to the web page otherwise.\u00a0 The contents of the file have been read into the variable &#8220;fileContent&#8221; in this case, then use this VBscript to check for and remove it:<\/p>\n<pre><span style=\"color: green;\"><em>'remove BOM if present http:\/\/unicode.org\/faq\/utf_bom.html\r\n<\/em><\/span><span style=\"color: red;\"><strong>If<\/strong><\/span> <span style=\"color: blue; font-size: xx-small;\"><strong>(<\/strong><\/span><span style=\"color: red;\"><strong>Len<\/strong><\/span><span style=\"color: blue; font-size: xx-small;\"><strong>(<\/strong><\/span>Trim<span style=\"color: blue; font-size: xx-small;\"><strong>(<\/strong><\/span>fileContent<span style=\"color: blue; font-size: xx-small;\"><strong>)<\/strong><\/span><span style=\"color: blue; font-size: xx-small;\"><strong>)<\/strong><\/span> <span style=\"color: blue; font-size: xx-small;\"><span style=\"color: blue; font-size: xx-small;\">&gt;<\/span><\/span> <span style=\"color: brown;\">0<\/span><span style=\"color: blue; font-size: xx-small;\"><strong>)<\/strong><\/span> <span style=\"color: red;\"><strong>Then<\/strong><\/span>\r\n  <span style=\"color: red;\"><strong>Dim<\/strong><\/span> AscValue <span style=\"color: blue; font-size: xx-small;\">:<\/span> AscValue <span style=\"color: blue; font-size: xx-small;\"><span style=\"color: blue; font-size: xx-small;\">=<\/span><\/span> <span style=\"color: red;\"><strong>Asc<\/strong><\/span><span style=\"color: blue; font-size: xx-small;\"><strong>(<\/strong><\/span>Trim<span style=\"color: blue; font-size: xx-small;\"><strong>(<\/strong><\/span>fileContent<span style=\"color: blue; font-size: xx-small;\"><strong>)<\/strong><\/span><span style=\"color: blue; font-size: xx-small;\"><strong>)<\/strong><\/span>\r\n  <span style=\"color: red;\"><strong>If<\/strong><\/span> <span style=\"color: blue; font-size: xx-small;\"><strong>(<\/strong><\/span><span style=\"color: blue; font-size: xx-small;\"><strong>(<\/strong><\/span>AscValue <span style=\"color: blue; font-size: xx-small;\"><span style=\"color: blue; font-size: xx-small;\">=<\/span><\/span> <span style=\"color: blue; font-size: xx-small;\"><span style=\"color: blue; font-size: xx-small;\">-<\/span><\/span><span style=\"color: brown;\">15441<\/span><span style=\"color: blue; font-size: xx-small;\"><strong>)<\/strong><\/span> <span style=\"color: blue;\">Or<\/span> <span style=\"color: blue; font-size: xx-small;\"><strong>(<\/strong><\/span>AscValue <span style=\"color: blue; font-size: xx-small;\"><span style=\"color: blue; font-size: xx-small;\">=<\/span><\/span> <span style=\"color: brown;\">239<\/span><span style=\"color: blue; font-size: xx-small;\"><strong>)<\/strong><\/span><span style=\"color: blue; font-size: xx-small;\"><strong>)<\/strong><\/span> <span style=\"color: red;\"><strong>Then<\/strong><\/span> <span style=\"color: blue; font-size: xx-small;\">:<\/span> fileContent <span style=\"color: blue; font-size: xx-small;\"><span style=\"color: blue; font-size: xx-small;\">=<\/span><\/span> <span style=\"color: red;\"><strong>Mid<\/strong><\/span><span style=\"color: blue; font-size: xx-small;\"><strong>(<\/strong><\/span>Trim<span style=\"color: blue; font-size: xx-small;\"><strong>(<\/strong><\/span>fileContent<span style=\"color: blue; font-size: xx-small;\"><strong>)<\/strong><\/span><span style=\"color: blue; font-size: xx-small;\"><strong>,<\/strong><\/span><span style=\"color: brown;\">4<\/span><span style=\"color: blue; font-size: xx-small;\"><strong>)<\/strong><\/span> <span style=\"color: blue; font-size: xx-small;\">:<\/span> <span style=\"color: red;\"><strong>End<\/strong><\/span> <span style=\"color: red;\"><strong>If<\/strong><\/span>\r\n<span style=\"color: red;\"><strong>End<\/strong><\/span> <span style=\"color: red;\"><strong>If<\/strong><\/span><\/pre>\n<p>&nbsp;<\/p>\n<p><!--\n'remove BOM if present http:\/\/unicode.org\/faq\/utf_bom.html\nIf (Len(Trim(fileContent)) > 0) Then\n  Dim AscValue : AscValue = Asc(Trim(fileContent))\n  If ((AscValue = -15441) Or (AscValue = 239)) Then : fileContent = Mid(Trim(fileContent),4) : End If\nEnd If\n--><\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>I wasn&#8217;t able to find much on this with web searching (enough to be able to cobble together this solution, but that&#8217;s it!)&#8230; so thought I&#8217;d post it in case it helps others.\u00a0 I needed to remove the &#8220;byte order mark&#8221; (BOM) from the beginning of a file that had been read into a variable &#8230;<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_post_was_ever_published":false},"categories":[43],"tags":[145,147,146],"class_list":{"0":"post-226","1":"post","2":"type-post","3":"status-publish","4":"format-standard","6":"category-web-stuff","7":"tag-asp-classic-bom-vbscript","8":"tag-byte-order-mark","9":"tag-utf-8","10":"anons"},"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/peSL2o-3E","jetpack_sharing_enabled":true,"jetpack_likes_enabled":false,"_links":{"self":[{"href":"https:\/\/bdragon.com\/lair\/wp-json\/wp\/v2\/posts\/226","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/bdragon.com\/lair\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/bdragon.com\/lair\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/bdragon.com\/lair\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/bdragon.com\/lair\/wp-json\/wp\/v2\/comments?post=226"}],"version-history":[{"count":0,"href":"https:\/\/bdragon.com\/lair\/wp-json\/wp\/v2\/posts\/226\/revisions"}],"wp:attachment":[{"href":"https:\/\/bdragon.com\/lair\/wp-json\/wp\/v2\/media?parent=226"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/bdragon.com\/lair\/wp-json\/wp\/v2\/categories?post=226"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/bdragon.com\/lair\/wp-json\/wp\/v2\/tags?post=226"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}