Microsoft > Windows XP
MS-DOS 8.0: Determine String Length?
(1/1)
Ana21:
Using MS-DOS 8.0, what is the best way to determine the length of a string?
I looked through Computer Hope (http://www.computerhope.com/msdos.htm), but no commands jumped out at me...
Is there a built in command or must a function be built to address this?
Thanks a ton.
Sidewinder:
This might help:
--- Code: ---@echo off
setlocal
set /p var=Enter String Value:
:length
if defined var (set var=%var:~1%& set /a length+=1 & goto length)
echo String length is: %length% characters
--- End code ---
Quirk Alert: %& must be concatenated in "if defined" line
MS-DOS 8? Wow! 8)
patio:
Never heard of it...
clarkegriffinx:
--- Quote from: Ana21 on November 19, 2020, 03:03:29 AM ---Using MS-DOS 8.0, what is the best way to determine the length of a string?
I looked through Computer Hope (http://www.computerhope.com/msdos.htm), but no commands jumped out at me...
Is there a built in command or must a function be built to address this?
McDVOICE MyBKExperience Liteblue
Thanks a ton
--- End quote ---
I got and example and this is it cleaned up a litte
--- Code: ---@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
--- End code ---
Here's another option. Pass the string as a paramter like this:
--- Code: --- LEN "this is a long string"
--- End code ---
Here's the code:
--- Code: --- @echo off
echo.%~1>len
for %%a in (len) do set /a len=%%~za -2
echo %len%
--- End code ---
Copy and paste the code into Notepad and save it as LEN.BAT.
NOTE: The fullstop following the ECHO statement is vital should a NUL string be entered. The -2 is required because ECHO automatically adds a CR & LF at the end of each line.
Navigation
[0] Message Index
Go to full version