I am new to batch scripting. although i have shell and python solutions for this problem but got stuck in batch script.
I have string like 123_happy
,
I think this is the simplest way:
@echo off
setlocal
set "str=123_happy"
set /A num=str
echo Result = %num%
When set /A
command get a value from a variable, it convert the number until the first non-digit character with no error.
To preserve left zeros:
set "str=0128_happy"
set "num=1%str%"
set /A num=num
set "num=%num:~1%"
echo Result = %num%