Space - VBScript


The Space command in VBScript creates a string of a specified number of spaces. It is commonly used for formatting, alignment, and creating indentation in text.




  • number: The number of spaces to create.




' Create a string of 10 spaces
Dim myString = Space(10)
' Indent a line of text by 5 spaces
Dim myLine = "Hello, world!"
WScript.Echo Space(5) & myLine

Common Issues

  • Negative Number Argument: If a negative number is specified as the argument, an error will occur.
  • Unicode Encoding: The Space command always produces ASCII spaces, regardless of the current code page or system encoding. For Unicode spaces, use the ChrW function instead.


The Space command can be combined with other VBScript commands to create more complex formatting and indentation patterns. For example, it can be used with Trim to remove leading and trailing spaces from a string, or with Mid to extract a specific number of characters from a string.

  • ChrW: Creates a Unicode character.
  • Format: Formats a value using a specified format string.
  • Trim: Removes leading and trailing spaces from a string.