Solved

Delphi add BOM to files

Posted on 2014-04-23
6
589 Views
Last Modified: 2014-06-15
I want to add a utf8 bom to files that don't have it.

(ie 0xEF,0xBB,0xBF  in the beginning)

Can someone give me some code to check the 3 first bytes of a file and insert the bom if missing?
0
Comment
Question by:pucko73
  • 2
  • 2
  • 2
6 Comments
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 40019352
Why?  It's not recommended for files for the web.
0
 

Author Comment

by:pucko73
ID: 40019364
Tell that to the people that made the "parsing in the receiving application"  and that read all files without BOM as ANSI encoded.
0
 
LVL 83

Accepted Solution

by:
Dave Baldwin earned 500 total points
ID: 40019377
Ok, good reason.  I don't have the actual code to give you.  You need to open the files in binary mode and read those first bytes.  If they're not there, then you put them in the write buffer and read the rest of the file into it after them as basically a file copy routine.  Then write the file out, usually under a temp name, close the files delete the original, and rename the new version.
0
Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

 

Expert Comment

by:sepidehdam
ID: 40114349
Help to guide delphi 7
"ALTER TABLE add column.
By coding with Delphi 7
0
 

Expert Comment

by:sepidehdam
ID: 40114411
Help to guide delphi 7
"ALTER TABLE add column.
By coding with Delphi 7
0
 

Author Comment

by:pucko73
ID: 40136264
???
0

Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Delphi procedure  - Unsatisfied forward or external declaration. 2 162
Delphi 2 61
Create a path if not exists 7 78
Sending files from  idTcpServer Socket to idTcpClient 2 40
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

832 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question