0

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.

1 Answers1

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