MS-DOS 8.0: determining line length?

Using MS-DOS 8.0, what's the best way to determine the length of a string?

I looked at Computer Hope (http://www.computerhope.com/msdos.htm), but no commands popped up on me ...

Is there a built-in command or should a function be built to solve this problem?

Thanks a ton.

+3
source share
3 answers

From here I got an example, and he cleaned it litte

@echo off
setlocal
set #=%1
set length=0
:loop
if defined # (set #=%#:~1%&set /A length += 1&goto loop)
echo %1 is %length% characters long!
endlocal

alt text

+3
source

Here is another option. Pass the string as a parameter:

   LEN "this is a long string"

Here is the code:

   @echo off

   echo.%~1>len
   for %%a in (len) do set /a len=%%~za -2

   echo %len%

Copy and paste the code into Notepad and save it as LEN.BAT.

. ECHO , NUL. -2, ECHO CR LF .

+2

I regularly use the following method:

   @echo off
   set str=This is a line of text

   echo.%str%>len
   for %%a in (len) do set /a len=%%~za -2

   echo %len%
+1
source

Source: https://habr.com/ru/post/1773171/


All Articles