I'm trying to make a batch file to solve a puzzle. At my current moment I need a way to detect the length of a string. I don't really know where to start and did not find any related articles on a title search.
Asked
Active
Viewed 1,944 times
0
-
2try https://stackoverflow.com/search?q=string+length+batch – Magoo Feb 25 '18 at 08:41
-
@Magoo Unfortunately my searches were poor, Apparrently... – Fierce Thunder Feb 25 '18 at 12:55
1 Answers
0
@echo off
setlocal enabledelayedexpansion
set "line=this is my string"
for /l %%a in (0,1,8191) do (
Set "each=!line:~%%a,1!"
if not defined each echo length: %%a & endlocal & set length=%%a & goto :eof
)
If you want to test the length of the string excluding special characters or whitespace you need to remove whitespace and escape special characters before setting each

Gerhard
- 22,678
- 7
- 27
- 43