Batch Script Tutorial on Batch Script Strings

in dos, a string is an ordered collection of characters, such as "hello, world!".

s.no strings & description
1 create string

a string can be created in dos in the following way.

2 empty string

empty string

3 string interpolation

string interpolation is a way to construct a new string value from a mix of constants, variables, literals, and expressions by including their values inside a string literal.

4 string concatenation

you can use the set operator to concatenate two strings or a string and a character, or two characters. following is a simple example which shows how to use string concatenation.

5 string length

in dos scripting, there is no length function defined for finding the length of a string. there are custom-defined functions which can be used for the same. following is an example of a custom-defined function for seeing the length of a string.

6 toint

a variable which has been set as string using the set variable can be converted to an integer using the /a switch which is using the set variable. the following example shows how this can be accomplished.

7 align right

this used to align text to the right, which is normally used to improve readability of number columns.

8 left string

this is used to extract characters from the beginning of a string.

9 mid string

this is used to extract a substring via the position of the characters in the string.

10 remove

the string substitution feature can also be used to remove a substring from another string.

11 remove both ends

this is used to remove the first and the last character of a string.

12 remove all spaces

this is used to remove all spaces in a string via substitution.

13 replace a string

to replace a substring with another string use the string substitution feature.

14 right string

this is used to extract characters from the end of a string.