forked from Batch-Man/BatCenter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGetlen.bat
64 lines (54 loc) · 1.88 KB
/
Getlen.bat
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
@echo off
::LINE ADDED HERE
set "_text=%~1"
Setlocal EnableDelayedExpansion
REM This Getlen function 3.0 is not created by Kvc...but it is modified and enhanced by kvc & Sounak@9434...
REM I don't Know about the original Programmer, but I appriciate his/her work...
REM The algorithm of this program repeats for loop only 13 times for each call from the main batch file...
REM It makes it fast and efficient for calculating the length of longer strings...
REM It can calculate upto 8100 aprox. characters...
REM Get More Extensions Like this @ www.thebateam.org
REM It is an upgrade to the older getlen.exe function, which was created using cpp's getlen function...
Set ver=3.0
REM Setting up initial length...
set len=0
REM Checking for various inputs to the fucntion...
::REPLACED ALL VARIABLES
IF /i "!_text!" == "" (Goto :End)
IF /i "!_text!" == "/h" (Goto :Help)
IF /i "!_text!" == "/?" (Goto :Help)
IF /i "!_text!" == "-h" (Goto :Help)
IF /i "!_text!" == "Help" (Goto :Help)
IF /i "!_text!" == "ver" (Echo.%ver% && Goto :EOF)
:Main
::REPLACED INPUT VARIABLE
set "s=!_text!#"
for %%P in (4096 2048 1024 512 256 128 64 32 16 8 4 2 1) do (
if "!s:~%%P,1!" NEQ "" (
set /a "len+=%%P"
set "s=!s:~%%P!"
)
)
:End
REM The Method Used below is called 'Tunneling in batch'...
REM Using the variable of previous block in new block...
Endlocal && Exit /b %len%
:Help
Echo.
Echo. Calculates the Length of The Given String.
Echo.
Echo. Syntax: Call Getlen [ver ^| String]
Echo. Where
Echo.
Echo. String: It is the String, Whose length to be calculated.
Echo.
Echo. The length of the string is Returned in to the Main fucntion through the
Echo. Environmental Errorlevel variable.
Echo.
Echo. Try these lines in a Batch file: [E.g.]
Echo.
Echo. Call Getlen "Karan Veer Chouhan"
Echo. Echo. %%Errorlevel%%
Echo.
ECHo. #TheBATeam
Goto :End