如何批量去除负数中的负号

How to remove negative symbols from negative numbers in batch

我正在设置一行文本,告诉您是否失去或获得了某些东西,但只要值为负,(-) 符号始终存在。我试图搜索如何解决这个问题,但没有找到任何东西。

:grocerycomplete
set /a randomsurvivors=%random% %%3 - 1
if %randomsurvivors% LSS 0 (
    set porn=lost
) else (
    set porn=gained
)
echo ========================
echo You have looted the Grocery Store!
echo You have %porn% %randomsurvivors% Survivor(s)!

"randomsurvivors" 生成一个介于 1 和 -1 之间的数字。

The number is then read and if it is <0 it will say lost and if it >0 it will say gained. Whenever it is -1 it will say:

========================
You have looted the Grocery Store!
You have lost -1 Survivor(s)!

我想让它说:

========================
You have looted the Grocery Store!
You have lost 1 Survivor(s)!

只需要一个很小的改动(最后一行三个字符):

:grocerycomplete
set /a randomsurvivors=%random% %%3 - 1
if %randomsurvivors% LSS 0 (
    set porn=lost
) else (
    set porn=gained
)
echo ========================
echo You have looted the Grocery Store!
echo You have %porn% %randomsurvivors:-=% Survivor(s)!

使用 substring substitution- 替换为空。