Samstag, 29. März 2008

BATCHLIB_ Batchlib package v1.0

Download
Batchlib package v1.0 (5 KB zip file)

What is it?
Inspired by my library idea, I created a package containing several libraries with subroutines that I need more or less often.

What Libraries are contained?
Currently, the following libraries are contained in the package:
How to use the libraries?
Place the libraries in a subdirectory named "lib" of your batch script(s). To call the subroutine :TRIM of the string.cmd library, use the following code:
SET MY_STRING=    A string with spaces around the text   
CALL %~dps0lib\string.cmd :TRIM "%MY_STRING%"
ECHO Trimmed string is '%RESULT%'.

License
This work is licensed under the Creative Commons Attribution-Noncommercial 2.0 Germany (Namensnennung-Keine kommerzielle Nutzung 2.0 Deutschland).

History
  • v1.0 2008-03-29 First release

BATCHLIB_ Batchlib library string.cmd

The batchlib library string.cmd is part of the batchlib package. It provides the following subroutines:

:STRLEN: Returns the string length.
:SUBSTR: Extracts a substring. Works exactly the same the string substitution function %VAR:~x,y% does.
:TRIM: Trims whitespace at beginning and end of a string.
:GET_ASCII_CHARS: Returns a string containing all ASCII characters at their given offset.
:ASC2HEX: Converts the ASCII string to a space separated list of hex numbers.
:ASC2DEC: Converts an ASCII string to a space separated list of decimal numbers.
:HEX2ASC: Converts a list of hexadecimal numbers to an ASCII string.
:DEC2ASC: Converts a list of decimal numbers to an ASCII string.
:ASCII: Returns the numeric (decimal) ASCII code of the character.
:CHAR: Returns the ASCII character denoted by the decimal number.



Integer :STRLEN String
Returns the string length.
Parameters:
  1. string
Returns:
string length
Since: 1.0



String :SUBSTR String Integer Integer?
Extracts a substring. Works exactly the same the string substitution function %VAR:~x,y% does. Provides a way for dynamically extracting substrings.
Parameters:
  1. string to extract substring of
  2. x; 0 or greater: string offset, negative number: string offset from end
  3. (default -0) y; 0 or greater: number of characters to extract, negative number: string offset from end where to stop substring extraction
Returns:
substring
Since: 1.0



String :TRIM String
Trims whitespace at beginning and end of a string.
Parameters:
  1. string to trim
Returns:
trimmed string
Since: 1.0



String :GET_ASCII_CHARS
Returns a string containing all ASCII characters at their given offset. All (in batch) non-printable characters will be replaced by a space.
Returns:
all ASCII characters
Since: 1.0



String[] :ASC2HEX String Boolean? String?
Converts the ASCII string to a space separated list of hex numbers. For example "ABC" will be converted to "41 42 43".
Parameters:
  1. ASCII string
  2. (default false) use 0x prefix
  3. (default " ") separator string
Returns:
list of hex numbers
Since: 1.0



Integer[] :ASC2DEC String String?
Converts an ASCII string to a space separated list of decimal numbers. For each character in the the string it's decimal ASCII index will be used. For example the string "ABC" will be converted to "65 66 67".
Parameters:
  1. ASCII string
  2. (default " ") list item separator string
Returns:
list of decimals
Since: 1.0



String :HEX2ASC String[] String?
Converts a list of hexadecimal numbers to an ASCII string. Automatically detects if numbers are prefixed with "0x".
Parameters:
  1. hexadecimal list
  2. (default " ") list item separator
Returns:
ASCII string
Since: 1.0



String :DEC2ASC Integer[] String?
Converts a list of decimal numbers to an ASCII string.
Parameters:
  1. decimal list
  2. (default " ") list item separator string
Returns:
ASCII string
Since: 1.0



Integer :ASCII String
Returns the numeric (decimal) ASCII code of the character.
Parameters:
  1. single character
Returns:
ASCII code
Since: 1.0



String :CHAR Integer
Returns the ASCII character denoted by the decimal number. Non-printable characters will be returned as space.
Parameters:
  1. ASCII offset number of character
Returns:
ASCII character
Since: 1.0

Reflog

Informationstechnische Howtos, Hinweise und Merkwürdiges

Batchlib v1.0 2008-03-29

Aktuelle Beiträge

HOWTO_ O2 DSL Surf &...
Der O2 DSL Surf & Phone-Router ist für die alleinige...
cypressor - 12. Feb, 19:57
Uptweak Windows XP Home...
There are a lot of annoying limitations in Windows...
cypressor - 9. Okt, 19:30
BATCHLIB_ Batchlib package...
Download Batchlib package v1.0 (5 KB zip file) What...
cypressor - 29. Mär, 19:10
BATCHLIB_ Batchlib library...
The batchlib library string.cmd is part of the batchlib...
cypressor - 29. Mär, 18:10

Homepage Ticker

Links

Status

Online seit 6816 Tagen
Zuletzt aktualisiert: 28. Jun, 11:32
RSS XML 1.0 Button-Get-Firefox

batch
batchlib
howto
tech
video
Profil
Abmelden
Weblog abonnieren