echo -e 在 Windows 中等效吗? [英] echo -e equivalent in Windows?

查看:37
本文介绍了echo -e 在 Windows 中等效吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在windows中是否有任何Linuxecho -e"等价物,以便我可以使用echo -e xnnn"打印出ASCII码为十六进制值nnn的字符?

Is there any Linux "echo -e" equivalent in windows so I can use "echo -e xnnn" to print out the character whose ASCII code is the hexadecimal value nnn ?

推荐答案

没有等效的,但你可以编写自己的函数.

There is no equivalent, but you can write your own function.

我会把问题分成两部分.

I would split the problem into two parts.

  • 将十六进制数转换为十进制数.
  • 将十进制数转换为 ASCII.

从十六进制转换为十进制很简单

Converting from hex to decimal is simple by

set "myHex=4A"
set /a decimal=0x%myHex%

将数字转换为 ASCII 更加棘手,这取决于所需的 ASCII 范围
如果您只需要从 32(空格)到 126'~' 的范围,您可以使用 =ExitCodeAscii 变量

Converting a number to an ASCII is more tricky, it depends of the required ASCII-range
If you only need the range from 32 (space) to 126'~', you could use the =ExitCodeAscii variable

set "decimal=%1"
cmd /c exit /b %decimal%
echo "%=ExitCodeAscii%"

如果你还需要CRLFESCDEL等特殊字符,可以使用纯批处理创建它们.

If you need also some special characters like CR, LF, ESC, DEL, it is possible to create them with pure batch.

如果您需要的比 vbscript 多.

If you need more than you could use vbscript.

更通用的方法是使用命令 forfiles (Dostips: 生成几乎任何字符...)

A more general way is to use the command forfiles (Dostips: Generate nearly any character...)

echo-e.bat

@echo off
set "arg1=%~1"
set "arg1=%arg1:x=0x%"
forfiles /p "%~dp0." /m "%~nx0" /c "cmd /c echo(%arg1%"

可以通过 echo-e.bat "Hellox01x02x03" 调用然后你得到Hello☺☻♥.

You can call it via echo-e.bat "Hellox01x02x03" and you get Hello☺☻♥.

这篇关于echo -e 在 Windows 中等效吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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