This multiline string when created by a browser has the expected length:
<script type="text/javascript">
var s = "\
a";
document.write(s.length);
</script>
Outputs 5
But when executed as ASP server side scritp it outputs 1:
<%@ Language=JavaScript %>
<%
var s = "\
a";
Response.Write(s.length);
%>
What is happening is that the ASP version of Javascript is eating the leading white spaces when used in multiline strings.
How to make the ASP version behave the same as the browser version?
If you include a
\at the start of your line, asp recognizes the whitespace.I wasn’t familiar with using the
\character to create multiline strings. Neat stuff, but I couldn’t find documentation for that. I guess it’s just escaping the line break? Do you have a link to a reference?Edit Additionally, this code:
Gives this output: