Well, if that's the fixed entry format, this will work:
@echo off
setlocal EnableDelayedExpansion
set /p macID="please enter mac id:"
call :print_token 0 2 -
call :print_token 2 2 -
call :print_token 4 2 -
call :print_token 7 2 -
call :print_token 9 2 -
call :print_token 11 2
goto :eof
:print_token
echo | set /p dummyVar=!macID:~%1,%2!%3
exit /b 0
Regarding the echo | set /p dummyVar=
, it is used to echo
values without line breaks. Take a look at this for further information.
If you expect a non-fixed input format, then you need to clean up extrange characters first, and then split like shown in this example. After cleaning the input value, you could easily turn the call :print_token
sequence into a for loop, for improved clarity.
Sample run:
please enter mac id:abcd12-34defg
ab-cd-12-34-de-fg