在两个ASP表达式代码之间被删除的空间

时间:2021-08-22 02:02:28

I'm new to ASP and have been tasked to update a file by a client. When I try to "echo" two variables with a space between them the space is being removed. Any ideas why?

我是ASP的新手,我的任务是更新一个客户端文件。当我试图用两个变量之间的空格“echo”时,空格被删除。任何想法为什么?

Here are two examples:

这里有两个例子:

<%
    Dim variable1, variable2
    variable1 = "Hello"
    variable2 = "there"
%>
<p><%= variable1 %> <%= variable2 %></p>

or

<p><% Response.write( variable1 ) %> <%= Response.write( variable2 ) %></p>

This writes: <p>Hellothere</p> without the space in between the two words. Am I doing something wrong? or is this normal to ASP?

这样写:

Hellothere

,没有空格在这两个单词之间。我做错什么了吗?或者这对ASP正常吗?

I've resorted to using the following, but am having a hard time believing that content outside of the <% %> would be getting removed.

我使用了下面的方法,但是我很难相信<% >之外的内容会被删除。

<% Response.Write( variable1 & " " & variable2 ) %>

Any help would be appreciated.

如有任何帮助,我们将不胜感激。

1 个解决方案

#1


2  

Yep. It's one of those things. Whitespace before or after code blocks (<%...%>) is considered part of the HTML document but whitespace between consecutive code blocks is ignored. You have a couple options:

是的。这是其中之一。代码块前后的空格(<%…%>)被认为是HTML文档的一部分,但是连续代码块之间的空格被忽略。你有几个选择:

  1. Insert &nbsp; between (explicit whitespace):

    插入,(显式之间空格):

    <p><%= variable1 %>&nbsp;<%= variable2 %></p>
    
  2. Write the full tag in a single ASP context:

    在单个ASP上下文中编写完整的标记:

    Response.Write "<p>" & variable1 & " " & variable2 & "</p>"
    ' or
    <p><%= variable1 & " " & variable2 %></p>
    

#1


2  

Yep. It's one of those things. Whitespace before or after code blocks (<%...%>) is considered part of the HTML document but whitespace between consecutive code blocks is ignored. You have a couple options:

是的。这是其中之一。代码块前后的空格(<%…%>)被认为是HTML文档的一部分,但是连续代码块之间的空格被忽略。你有几个选择:

  1. Insert &nbsp; between (explicit whitespace):

    插入,(显式之间空格):

    <p><%= variable1 %>&nbsp;<%= variable2 %></p>
    
  2. Write the full tag in a single ASP context:

    在单个ASP上下文中编写完整的标记:

    Response.Write "<p>" & variable1 & " " & variable2 & "</p>"
    ' or
    <p><%= variable1 & " " & variable2 %></p>