January 28th, 2014, 04:27 PM
I need to include multiple spaces in a variable value
I have a variable that has two parts. There MUST be 20 spaces between the first part and the second part. If I set the variable up as
my_var="part1 part2" (this page will not post the spaces either but when I look in the editor, there are 20 spaces between part1 and part2)
when i use response.write(my_var) it returns
How can I get it to retain the spaces?
Last edited by kjbmco; January 28th, 2014 at 04:29 PM.
January 28th, 2014, 04:32 PM
The spaces are actually there, they're just visually hidden from you. Unless told otherwise, HTML will "collapse" multiple spaces, tabs, and newlines into a single space character. The editor you just used is showing you that mechanism at work.
How to retain the spaces is not quite that simple. There are different ways, and which ones you use (and don't use) depend on circumstances...
Classic ASP? One way uses the Replace function:
That "&nbsp;" is the HTML entity representing a non-breaking space and HTML will not collapse them down like it would with a regular space.
Response.Write(Replace(my_var, " ", "&nbsp;"))
Last edited by requinix; January 28th, 2014 at 04:34 PM.
January 28th, 2014, 04:39 PM
Perfect Solution. Tried it and it worked. Thanks