I have a file which is encoded as UTF-8. I'd like to change it to UTF-8 + BOM.
This is what I wrote, but it didn't work:
write/binary %mycontacts.csv insert read/binary %mycontacts.csv #{EFBBBF}
What should I do?
When doing a pipeline of processing, the return result of INSERT is the series position you passed in:
>> str: "ution"
>> print insert str {Rebol}
ution
Note that if you use an intermediate variable (as above) then that variable will point to the beginning of your newly inserted content after the operation:
>> print str
Rebolution
If you don't want to use an intermediate variable, but want to get the beginning of your inserted content, you'll need to skip backwards the length of the content you inserted:
>> print skip insert str {Rebol} -5
Rebolution
But if you know you inserted at the head of the series then you can just use HEAD:
>> print head insert str {Rebol}
Rebolution
So because you're inserting at the head of the series for your byte-order marker, the following should work for your case:
write/binary %mycontacts.csv head insert read/binary %mycontacts.csv #{EFBBBF}