[Solved] Limit the characters of a variable? [closed]


@echo off
call :convert Hello
call :convert Hello beautiful World
call :convert Hello wooooooooooooooooooooooooooooooooorld
goto :eof

:convert
set "x=%*"
REM if the string is shorter than 10 chars, just print it and return:
if "%x:~10%" == "" echo %1 & goto :eof
REM else print first 7 chars, thee dots and the last three chars:
echo %x:~0,7%...%x:~-3%

Adapt the following numbers to your needs (you mentioned 30 chars, but none of your examples do match that number):
10 for “first ten characters” (due to zero-based counting it checks, if there is anything in the eleventh position)
7 for the number of characters before the three dots
3 for the number of last characters

solved Limit the characters of a variable? [closed]