首页 > 解决方案 > Powerbuilder:在没有 bom 的情况下将 UTF-8 转换为 UTF-8

问题描述

晚安,我需要在powerbuilder中将文本文件从UTF-8转换为没有bom的UTF-8我可以识别并应该从文本中删除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

标签: utf-8powerbuilder

解决方案


您将数据类型转换为text编码为blobUTF-8 并写下文件:

i=FileWriteEx(f, blob(text,EncodingUTF8!) )

推荐阅读