简体   繁体   English

回显带有前面空格但没有新行的文本

[英]echo text with preceding spaces but without new line

If I use <nul set/p= some text or set/p "= some text"<nul , preceding spaces are removed, even if I use character with 0xFF code. 如果我使用<nul set/p= some textset/p "= some text"<nul ,即使使用字符与0xFF代码,也会删除前面的空格。 How can I echo specified number of spaces at the beginning of the line w/o trailing CR/LF? 如何在不带尾随CR / LF的行的开头回显指定数量的空格?

Adding a backspace character works well at the start of the line. 在行的开头添加退格字符效果很好。

@echo off
:: define BS as a BackSpace character
for /f %%A in ('"prompt $H&for %%B in (1) do rem"') do set "BS=%%A"
set /p "=%bs%     some text"<nul
pause

a) If text is echoed on a new line, then just add backspace char in front of the output text. a)如果在新行上回显了文本,则只需在输出文本前面添加退格字符。
<nul set/p=[BS char here directly, without brackets] some text
In ANSI and ASCII codetables it has code 0x08 . 在ANSI和ASCII码表中,其代码为0x08
b) If the text needed to be placed as continuation of already existed line, then additionally add one non-space char before BS char, for example "Middle Dot" ( 0xFA ). b)如果需要将文本放置为已经存在的行的延续,则在BS char之前另外添加一个非空格char,例如“ Middle Dot”( 0xFA )。
<nul set/p=[MD char (0xFA), then BS char (0x08)] some text
Works fine in WinXP and Win7. 在WinXP和Win7中可以正常工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM