Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.
length of a string in a batch file
Name: bob cat Date: July 30, 2003 at 06:22:49 Pacific OS: windows 2000 sp3 CPU/Ram: p3 800mhz/512M
Comment:
I need to find the length of a string (variable actually) in a batch file, does anyone know how to do this simply?
Name: Secret_Doom Date: July 30, 2003 at 10:39:49 Pacific
Reply:
This will do it:
:: Send the length of the variable %MyVar% :: to the variable %length% set #=%MyVar% set length=0 :loop if defined # (set #=%#:~1%&set /A length += 1&goto loop) echo MyVar is %length% characters long!
Name: bob cat Date: July 30, 2003 at 11:25:47 Pacific
Reply:
excellent! just what I was looking for.
Thanks.
0
Response Number 3
Name: bunder Date: August 28, 2003 at 09:03:47 Pacific
Reply:
I'm getting a syntax error when I try to use this code. Any thoughts as to why this might be happening? One thing I notice is that the command interpreter removes the %#:~1% bit. Is this by design?
Summary: I never thought of using echo to test this! The line length for echo is over 300 characters (WinME--is that DOS 7?), but it depends on whether they are spaces or Ascii characters! I found a MS KB arti...
Summary: hi: I want to write a batch file so that the following info is put into a text file: user name computer name log in date as each new user logs onto my network, the above info is put into the text file...
Summary: To Delete a dir and all contents ... deltree [drive:/path/dirtobedeleted] So you woulden't want to type something like c:>deltree c:\windows ;-) -------------------------------- To format a MASTER dri...