Remove Byte-Order Mark (BOM) In Classic ASP, VBScript

 Web Stuff  Comments Off on Remove Byte-Order Mark (BOM) In Classic ASP, VBScript
May 192011
 
I wasn't able to find much on this with web searching (enough to be able to cobble together this solution, but that's it!)... so thought I'd post it in case it helps others.  I needed to remove the "byte order mark" (BOM) from the beginning of a file that had been read into a variable in a classic asp page (VBscript).  The BOM was output to the web page otherwise.  The contents of the file have been read into the variable "fileContent" in this case, then use this VBscript to check for and remove it:
'remove BOM if present http://unicode.org/faq/utf_bom.html
If (Len(Trim(fileContent)) > 0) Then
  Dim AscValue : AscValue = Asc(Trim(fileContent))
  If ((AscValue = -15441) Or (AscValue = 239)) Then : fileContent = Mid(Trim(fileContent),4) : End If
End If