【问题标题】:Batch Script SET /p entering special spanish characters批处理脚本 SET /p 输入特殊的西班牙语字符
【发布时间】:2012-05-27 10:48:43
【问题描述】:

根据我设置变量的方式,我得到不同的结果

案例一

@echo off
set TITLE=Cañete
setlocal EnableDelayedExpansion
set "line=<docTitle><text>%TITLE%</text></docTitle>"
( echo !line! ) > test1.txt

案例 2

set /P TITLE=     ( I introduce here the same word Cañete )
setlocal EnableDelayedExpansion
set "line=<docTitle><text>%TITLE%</text></docTitle>" 
( echo !line! ) > test2.txt

我在 test1.txt 中获得了正确的文本:

<docTitle><text>Cañete</text></docTitle>

在test2.txt中,我得到了错误的txt:

<docTitle><text>ca¤ete</text></docTitle>

我的问题:我如何才能在案例 2 中获得正确的

<docTitle><text>Cañete</text></docTitle>

非常感谢。

【问题讨论】:

    标签: variables batch-file set


    【解决方案1】:

    将 CHCP 命令应用于第二个代码:

    SET /P TITLE=     ( I introduce here the same word Cañete )
    SETLOCAL ENABLEDELAYEDEXPANSION
    CHCP 1252 > NUL
    SET "line=<docTitle><text>%TITLE%</text></docTitle>" 
    ( 
        ECHO !line! 
    ) > test2.txt
    CHCP 850 > NUL
    

    我希望我有所帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-03-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-07-12
      相关资源
      最近更新 更多