问题描述
大家下午好。
我正在为我们的电子发票供应商生成一个文本文件,以数字方式确定并生成XML和PDF文件我工作的公司。
我在VB NET 2017中使用FileOpen命令,我曾经使用VB 6.0和VB Net 2010几年以前,事实上,我正在正确创建输出文本文件。
这是代码:
Good Afternoon everybody.
I'm trying to generate a text file for our Electronic Invoicing supplier to digitally firm and generate the XML and the PDF file for the company I work in.
I'm using the "FileOpen" command in VB NET 2017, just I used to do with VB 6.0 and VB Net 2010 a few years ago, and in fact, I'm creating the output text file correctly.
this is the code:
strFileName = strPath + "Facturas_Texto\" + IDFiscal + ".txt"
If System.IO.File.Exists(strFileName) Then
System.IO.File.Delete(strFileName)
End If
FileOpen(1, strFileName, OpenMode.Output)
我正在使用打印语句逐一编写所需的行。
现在要点是我们的供应商希望文件包含UTF-8并避免BOM。
我已经读过这个编码字符并且避免BOM是一个问题构建HTML和XML文件,但我从未尝试过在文本文件中实现这一点,特别是通过VB net 2017生成它。
我看到我可以通过笔记本编辑文件并使用此UTF-8编码保存,但我需要通过vB网络代码进行保存。
我真的很感激任何帮助,或建议如何做到这一点或在哪里寻找有关它的信息。
非常感谢。
我尝试了什么:
我正在通过互联网搜索,试图找到一种方法来做到这一点。
I'm using the statement "Print" to write the required lines one by one.
The point now is our vendor wants the file enconding with UTF-8 and avoid BOM.
I have read this encoding characters and avoiding the BOM was a matter of building HTML and XML files, but I´ve never tried before to achieve this in a text file, specially generating it thru VB net 2017.
I saw I can edit the file thru the notebook and save it with this UTF-8 encoding, but I need to do it via the vB net code.
I'd really appreciate any help, or suggestion about how to do this or where to look for information about it.
Thank you very much.
What I have tried:
I am searching thru the Internet trying to find a way to do this.
推荐答案
要实例化不提供BOM的UTF8编码,请调用UTF8Encoding构造函数的任何重载。
所以,我建议阅读 []参数设置为 false
并且 true
。
[/ EDIT]
注意:如果您想使用数据进行进一步处理,可以直接将其写入xml。
请参阅:
[ ]
]
[ ]
[]
So, i'd suggest to read UTF8Encoding Constructor (Boolean, Boolean) (System.Text)[^] with parameters set to false
and true
.
[/EDIT]
Note: if you want to use data for further processing, you can write it into xml directly.
See:
XML Serialization – Tips & Tricks[^]
XML Serialization and Deserialization: Part-1[^]
XML Serialization and Deserialization: Part-2[^]
A Complete Sample of Custom Class Collection Serialization and Deserialization[^]
这篇关于从VB net创建一个编码为UTF-8的文本文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!