Tech Tip: Code Snippet: removing BOM from a document or blob
PRODUCT: 4D | VERSION: 13.2 | PLATFORM: Mac & Win
Published On: November 20, 2012
Removing the Byte-Order-Mark (BOM) from a blob can be accomplished with the following code:
CONVERT FROM TEXT(Convert to text($blob;"utf-8");"utf-8";$blob) |
Here is a method that utilizes this technique for removing the BOM from a document:
$vhDocRef:=Open document("") // Select the document of your choice If (OK=1) // If a document has been chosen CLOSE DOCUMENT($vhDocRef) // We don't need to keep it open DOCUMENT TO BLOB(Document;$docBlob) // Load the document If (OK=0) // Handle error Else // OK! CONVERT FROM TEXT(Convert to text($docBlob;"utf-8");"utf-8";$docBlob) BLOB TO DOCUMENT(Document;$docBlob) End if End if |
Using the method above, you are first prompted to open a file. The file is then loaded into a Blob and then converted back and forth in order to remove the BOM. The Blob is then saved back to disk.