批处理文件中的ANSI/Unicode冲突 [英] ANSI / Unicode conflict in batch file
问题描述
我有一些批处理文件,这些批处理文件使用文本文件来实现语言独立性.直到昨天,一切都很好...但是后来我开始将标准文本翻译成荷兰语和德语.两种语言都使用所谓的变音或重音符,例如ä,ë,ö.我认为西班牙语也会给ñ带来同样的问题.我使用标准编码(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%
当ECHO
为ON
时,表明没有从文件中读取任何行,或者从不执行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.
GUI程序
ñ 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屋!