INPUT Statement Removes Unquoted Leading and Trailing Spaces (37897)



The information in this article applies to:

  • Microsoft QuickBASIC 1.0
  • Microsoft QuickBASIC 1.01
  • Microsoft QuickBASIC 1.02
  • Microsoft QuickBASIC 1.0a
  • Microsoft QuickBASIC 2.0
  • Microsoft QuickBASIC 2.01
  • Microsoft QuickBASIC 3.0
  • Microsoft QuickBASIC 4.0
  • Microsoft QuickBASIC 4.0b
  • Microsoft QuickBASIC 4.5
  • Microsoft BASIC Compiler for MS-DOS and OS/2 6.0
  • Microsoft BASIC Compiler for MS-DOS and OS/2 6.0b
  • Microsoft Basic Professional Development System (PDS) for MS-DOS and MS OS/2 7.0
  • Microsoft Basic Professional Development System (PDS) for MS-DOS and MS OS/2 7.1
  • Microsoft GW-Basic Interpreter 3.20
  • Microsoft GW-Basic Interpreter 3.22
  • Microsoft GW-Basic Interpreter 3.23
  • Microsoft QuickBASIC Compiler for the Apple Macintosh 1.0
  • Microsoft QuickBASIC Compiler for the Apple Macintosh 1.0a
  • Microsoft QuickBASIC Compiler for the Apple Macintosh 1.0b
  • Microsoft BASIC Compiler
  • Microsoft BASIC Interpreter for Apple Macintosh 1.0
  • Microsoft BASIC Interpreter for Apple Macintosh 1.01
  • Microsoft BASIC Interpreter for Apple Macintosh 2.0
  • Microsoft BASIC Interpreter for Apple Macintosh 2.1
  • Microsoft BASIC Interpreter for Apple Macintosh 3.0

This article was previously published under Q37897

SUMMARY

In all versions of Microsoft Basic, the INPUT statement will remove leading and trailing spaces without quotation marks from an input string. The following two processes will help you work around this behavior:

  • Put double quotation marks around the input string.
  • Use LINE INPUT into a string variable.

MORE INFORMATION

Code Example

' Run this program and input the following with leading and
' trailing spaces:       test
INPUT X$
PRINT X$,LEN(X$)
' You must surround leading and trailing spaces in your input with
' double quotation marks to make them significant: "    test    "
' or else use LINE INPUT:
LINE INPUT X$
				

Modification Type:MinorLast Reviewed:8/16/2005
Keywords:KB37897