Good Night,我需要在powerbuilder中将文本文件从UTF-8转换为UTF-8而不使用bom。我可以识别并删除文本中的bom,但当我重新录制时,请帮助我继续使用bom。
integer li_fnum
long ll_bytes
li_fnum = FileOpen(ls_archivo, StreamMode!)
ll_bytes = FileReadEx(li_fnum, lblb_file_contents)
if len(lblb_file_contents) >= 3 then
GetByte(lblb_file_contents, 1, lbt_1)
GetByte(lblb_file_contents, 2, lbt_2)
GetByte(lblb_file_contents, 3, lbt_3)
if lbt_1 = 239 and lbt_2 = 187 and lbt_3 = 191 then // BOM for UTF8 = EF BB BF
// BOM is found - remove it from the blob
lblb_file_contents = BlobMid(lblb_file_contents, 4, len(lblb_file_contents) - 3)
// Check the truncated contents once again
if len(lblb_file_contents) = 0 then
MessageBox("Error", "There's no data in the file!", StopSign!)
return
end if
end if
end if
发布于 2020-08-14 23:18:58
将数据类型text
转换为使用UTF-8编码的blob
,并写下文件:
i=FileWriteEx(f, blob(text,EncodingUTF8!) )
发布于 2021-08-17 22:26:30
Create function remove_utf8_bom (String as_file)
Integer li_fnum
Long ll_bytes
String ls_file_contents
Blob lblb_file_contents
Byte lbt_1, lbt_2, lbt_3
li_fnum = FileOpen(as_file, StreamMode!)
ll_bytes = FileReadEx(li_fnum, lblb_file_contents)
FileClose(li_fnum)
if len(lblb_file_contents) >= 3 then
GetByte(lblb_file_contents, 1, lbt_1)
GetByte(lblb_file_contents, 2, lbt_2)
GetByte(lblb_file_contents, 3, lbt_3)
if lbt_1 = 239 and lbt_2 = 187 and lbt_3 = 191 then // BOM for UTF8 = EF BB BF
// BOM is found - remove it from the blob
lblb_file_contents = BlobMid(lblb_file_contents, 4, len(lblb_file_contents) - 3)
// Check the truncated contents once again
if len(lblb_file_contents) = 0 then
//MessageBox("Error", "There's no data in the file!", StopSign!)
return
end if
end if
end if
li_fnum = FileOpen(as_file, StreamMode!, Write!, Shared!, Replace!)
FileWriteEx(li_fnum, blob(string(lblb_file_contents, EncodingUTF8!),EncodingUTF8!) )
FileClose(li_fnum)
https://stackoverflow.com/questions/63146150
复制相似问题