:lTrim | strips white spaces (or other characters) from the beginning of a string |
:rTrim | strips white spaces (or other characters) from the end of a string |
:StartsWith | Tests if a text starts with a given string |
:strLen | returns the length of a string |
:toCamelCase | converts a string to camel case |
:toLower | converts uppercase character to lowercase |
:toUpper | converts lowercase character to uppercase |
:Trim | strip white spaces (or other characters) from the beginning and end of a string |
:trimSpaces | trims spaces around string variable |
:trimSpaces2 | trims spaces around string and assigns result to variable |
:Unique | returns a unique string based on a date-time-stamp, YYYYMMDDhhmmsscc |
Align Right | Align text to the right i.e. to improve readability of number columns. |
DOS - String Manipulation | Basic string manipulation in batch like you are used to from other programming languages. |
DOS - String Operations | Basic string operations in batch like you are used to from other programming languages. |
Left String | Extract characters from the beginning of a string. |
Map and Lookup | Use Key-Value pair list to lookup and translate values. |
Mid String | Extract a Substring by Position. |
Remove | Remove a substring using string substitution. |
Remove both Ends | Remove the first and the last character of a string. |
Remove Spaces | Remove all spaces in a string via substitution. |
Replace | Replace a substring using string substitution. |
Right String | Extract characters from the end of a string. |
Split String | Split a String, Extract Substrings by Delimiters. |
String Concatenation | Add one string to another string. |
Trim Left | Trim spaces from the beginning of a string via "FOR" command. |
Trim Quotes | Remove surrounding quotes via FOR command. |
Trim Right | Trim spaces from the end of a string via "FOR" command. |
Trim Right | Trim spaces from the end of a string via substitution. |
Description: | call:lTrim string char | ||
Script: |
|
Description: | call:rTrim string char max | ||
Script: |
|
Description: | call:StartsWith text string | ||
Script: |
|
Description: | call:strLen string len | ||
Script: |
|
Description: | call:toCamelCase str | ||
Script: |
|
Description: | call:toLower str | ||
Script: |
|
Description: | call:toUpper str | ||
Script: |
|
Description: | call:Trim string char max | ||
Dependencies: | :lTrim, :rTrim | ||
Script: |
|
Description: | call:trimSpaces varref | ||
Dependencies: | :trimSpaces2 | ||
Script: |
|
Description: | call:trimSpaces2 retval string | ||
Script: |
|
Description: | call:Unique ret | ||
Script: |
|
Description: | Add leading spaces to a string to make sure the output lines up. I.e. for variables no longer than 8 characters add 8 spaces at the front and then show only the last 8 characters of the variable. | ||
Script: |
|
||
Script Output: |
|
Description: | Similar to the Left function in VB a batch script can return a specified number of characters from the left side of a string by specifying a substring for an expansion given a position of 0 and a length using :~ while expanding a variable content. The example shows how to return the first 4 characters of a string. | ||
Script: |
|
||
Script Output: |
|
Description: | This example shows an approach to map a name of a month into it`s corresponding two digit number. The key-value pairs are listed in the map variable separated by semicolon. Key and value itself are separated by one dash character. Same can be used to tranlate a day-of-the-week short string into a day-of-the-week long string by changing the map content only. | ||
Script: |
|
||
Script Output: |
|
Description: | Similar to the Mid function in VB a batch script can return a specified number of characters from any position inside a string by specifying a substring for an expansion given a position and length using :~ while expanding a variable content. The example here shows how to extract the parts of a date. | ||
Script: |
|
||
Script Output: |
|
Description: | The string substitution feature can also be used to remove a substring from another string. The example shown here removes all occurrences of "the " from the string variable str. | ||
Script: |
|
||
Script Output: |
|
Description: | Using :~1,-1 within a variable expansion will remove the first and last character of the string. | ||
Script: |
|
||
Script Output: |
|
Description: | This script snippet can be used to remove all spaces from a string. | ||
Script: |
|
||
Script Output: |
|
Description: | To replace a substring with another string use the string substitution feature. The example shown here replaces all occurrences "teh" misspellings with "the" in the string variable str. | ||
Script: |
|
||
Script Output: |
|
Description: | Similar to the Right function in VB a batch script can return a specified number of characters from the right side of a string by specifying a substring for an expansion given a negative position using :~ while expanding a variable content. The example shows how to return the last 4 characters of a string. | ||
Script: |
|
||
Script Output: |
|
Description: | Use the FOR command to split a string into parts. The example shows how to split a date variable into its parts. | ||
Script: |
|
||
Script Output: |
|
Description: | This example shows how to add two strings in DOS. | ||
Script: |
|
||
Script Output: |
|
Description: | Use the FOR command to trim spaces at the beginning of a variable. In this example the variable to be trimmed is str. | ||
Script: |
|
||
Script Output: |
|
Description: | The FOR command can be used to safely remove quotes surrounding a string. If the string does not have quotes then it will remain unchanged. | ||
Script: |
|
||
Script Output: |
|
Description: | Trimming spaces at the end of a variable seems a little tricky. The following example shows how to use a FOR loop to trim up to 31 spaces from the end of a string. It assumes that Delayed Expansion is enabled. | ||
Script: |
|
||
Script Output: |
|
Description: | Trimming spaces at the end of a variable seems a little tricky. The following example shows how to use the string substitution feature to trim up to 31 spaces from the end of a string. It assumes that the string to be trimmed never contains two hash "##" characters in a row. | ||
Script: |
|
||
Script Output: |
|