通过批处理文件删除WMIC结果中不需要的空格 [英] Remove unwanted spaces in wmic results through batch file
问题描述
我正在处理一个批处理文件,其中我需要显示电池的剩余电量,我已经实现了我的目标,但是由于命令结果中存在多余和多余的空格,我对结果不满意.
Im working on a batch file in which I need to show the estimated charge remaining of the battery, I have achieved my goal but sadly I am not happy with the results due to excesive and unwanted spaces in the command result.
这是我的代码:
:charge
FOR /F "delims= skip=1" %%i IN ('WMIC PATH Win32_Battery Get EstimatedChargeRemaining') DO ( SET CHR=%%i
GOTO results )
:results
ECHO "Battery Percentage: %CHR%"
PAUSE
GOTO menu
以上命令的结果为:电池百分比:100"
如何在结果末尾去除那些空格?
How do I get rid of those spaces at the end of the result?
预先感谢,非常感谢您提供任何帮助.
Thanks in advance and any kind of help is greatly appreciated.
推荐答案
尝试如下:
:charge
@echo off
FOR /F "tokens=* delims=" %%i IN ('WMIC PATH Win32_Battery Get EstimatedChargeRemaining /format:value') DO (
for /f "tokens=* delims=" %%# in ("%%i") do set "%%#"
)
echo %EstimatedChargeRemaining%
WMIC添加了其他字符,但可以使用一个for循环将其删除-> https://www.dostips.com/forum/viewtopic.php?t=4266
WMIC adds additional character but it can be removed with one more for loop -> https://www.dostips.com/forum/viewtopic.php?t=4266
这篇关于通过批处理文件删除WMIC结果中不需要的空格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!