批处理文件中的 ANSI/Unicode 冲突 [英] ANSI / Unicode conflict in batch file

查看:45
本文介绍了批处理文件中的 ANSI/Unicode 冲突的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些批处理文件使用文本文件来实现语言独立.直到昨天一切正常……但后来我开始将标准文本翻译成荷兰语和德语.这两种语言都使用所谓的变音或重音字符,如 ä、ë、ö.我认为西班牙语也会给ñ 带来同样的问题.我使用标准编码(ANSI)使用记事本创建了文本文件.只需输入 (DOS: TYPE) 文件就会显示错误的重音字符:例如ë 显示为 Ù.在我编辑文本文件并以 Unicode 编码保存后,DOS TYPE 显示了我在记事本中输入的内容.在这一点上,我以为我的问题已经解决了……但我的批处理代码现在根本没有显示任何文字!批处理文件从文件中检索所有文本,如下所示(简化):

I have some batch files that use a text file for language-independancy. Until yesterday all worked fine ... but then I began translating the standard texts to Dutch and German. Both languages use so called diacritical or accented characters like ä, ë, ö. I think Spanish will give the same problems with ñ. I created the text file with Notepad using standard encoding, which is ANSI. Just typing (DOS: TYPE) the file showed the wrong accented characters: e.g. ë showed as Ù. After I edited the text file and saved with Unicode encoding the DOS TYPE showed exactly what I typed in Notepad. At this point I thought my problem was solved ... but my batch code now shows me no text at all! All text is retrieved from the file by a batch file that looks like this (simplified):

@rem Parms %1 text type number             File %%a program name
@rem       %2 program name (double quoted)      %%b  - - filler (tabs)
@rem       %3 text number                       %%c text number
@rem       %4 replacement value - 1             %%d  - - filler (tabs)
@rem       %5 replacement value - 2             %%e text string
set TempText=
set TempType=
setlocal enabledelayedexpansion
@rem Read file until both values are set ...
for /f  "usebackq tokens=1,2,3,4,5 delims=|" %%a in ("%EnvPath%Text.txt") do (
    if /i   %%a==Tools (if /i %%c==%1 (set  TempType=%%e))
    if /i   %%a==%~2   (if /i %%c==%3 (set  TempText=%%e))
    if not  "!TempType!"=="" (if not "!TempText!"=="" (goto :Leave))
)
:Leave
endlocal & set TempText=%TempText%&set TempType=%TempType%

ECHOON 时,它表明没有从文件中读取任何行或永远不会执行 FOR 循环.

When ECHO is ON it shows that no lines are read from the file or the FOR-loop is never executed.

我的问题是:如何让 FOR 循环读取 Unicode 文本?

My question is: how can I make the FOR loop to read the Unicode texts?

推荐答案

你的问题是cmd使用的是850代码页(在美国可能是437),输入chcp查看.英文 Windows 在其他地方使用 1252.

Your problem is that cmd uses code page 850 (in the US it may be 437), type chcp to see. English Windows uses 1252 elsewhere.

图形用户界面程序

ñ 0xf1

控制台程序

ñ 0xa4

如果您使用的是 32 位,请使用 edit.exe(一个 msdos 文本编辑器).否则,您可以使用 Word 并另存为 MSDos 文本.

If you are on 32 bit use edit.exe (a msdos text editor). Else you can use Word and save as MSDos text.

这篇关于批处理文件中的 ANSI/Unicode 冲突的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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