将vbCrLF附加到UCS-2 Little Endian [英] Append vbCrLF to UCS-2 Little Endian

查看:115
本文介绍了将vbCrLF附加到UCS-2 Little Endian的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在通过HP-UFT(以前的QTP)使用vbscript. 我面临的问题看起来很简单,但无法解决.

I'm using vbscript via HP-UFT (former QTP). I'm facing with issue which looks pretty simple but I couldn't fix it.

我从某些系统导出了.CSV文件,并且该文件中没有完成的CRLF.

I have .CSV files exported from some system and there is no finished CRLF in this file.

我需要一个简单的修复程序来对此文件追加新行(我知道这可能是写入另一个文件的解决方法) 我正在像这样使用FileSystemObject:

I need a simple fix to append new line to this file (I know that is possible write-to-another-file workaround) I'm using FileSystemObject like this:

Set objFile = objFSO.OpenTextFile(outFile,8)' (outFile,8, true/false/default)
objFile.Write "test string" & vbCrLf ' and other different combinations

我没有使用ADODB.Stream,因为它没有附加功能,也不需要其他文件

I didn't use ADODB.Stream because it has not append function and I have no need to additional files

尝试后在记事本中打开文件时,看到的是空正方形而不是CRLF.我认为是因为使用UCS-2 Little Endian编码创建的文件.我对utf-8没有这样的问题

When I'm opening file in Notepad after my tries I see empty squares instead CRLF. I think it because file created with UCS-2 Little Endian encoding. I have no such issue with utf-8

PS也许可以更快速地修复系统变量?我在网络中发现可以通过某些系统变量来更改所有创建文件的默认编码,但找不到它的名称. 我在区域和语言中的语言->管理->非Unicode语言是英语

PS maybe some more quick fix of system variable is possible? I have found in network that it possible to change default encoding for all created files via some system varibale but din't find it name. My Language in Region and Language -> Administrative -> Language for non-Unicode is English

推荐答案

如有疑问,请阅读

语法

object.OpenTextFile(filename[, iomode[, create[, format]]])

[...]
格式
选修的.用于指示已打开文件格式的三个 Tristate 值之一( TristateTrue = -1以Unicode格式打开文件, TristateFalse = 0要以ASCII格式打开文件,请 TristateUseDefault = -2以系统默认值打开文件).如果省略,该文件将以ASCII格式打开.

[...]
format
Optional. One of three Tristate values used to indicate the format of the opened file (TristateTrue = -1 to open the file as Unicode, TristateFalse = 0 to open the file as ASCII, TristateUseDefault = -2 to open the file as the system default). If omitted, the file is opened as ASCII.

您打开文件进行追加,但未指定编码,因此解释器采用ASCII格式.换行

You open the file for appending, but don't specify the encoding, so the interpreter assumes ASCII format. Change the line

Set objFile = objFSO.OpenTextFile(outFile,8)

Set objFile = objFSO.OpenTextFile(outFile, 8, False, -1)

问题将消失.

这篇关于将vbCrLF附加到UCS-2 Little Endian的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆