#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2014
    Posts
    2
    Rep Power
    0

    Question I need to include multiple spaces in a variable value


    Hello:

    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

    part1 part2

    How can I get it to retain the spaces?
    Last edited by kjbmco; January 28th, 2014 at 03:29 PM. Reason: clarity
  2. #2
  3. Transforming Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,122
    Rep Power
    9398
    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:
    Code:
    Response.Write(Replace(my_var, " ", " "))
    That " " is the HTML entity representing a non-breaking space and HTML will not collapse them down like it would with a regular space.
    Last edited by requinix; January 28th, 2014 at 03:34 PM.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2014
    Posts
    2
    Rep Power
    0
    Perfect Solution. Tried it and it worked. Thanks

IMN logo majestic logo threadwatch logo seochat tools logo