Solved

Delphi add BOM to files

Posted on 2014-04-23
6
576 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 82

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 82

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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

707 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now