Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > How to stop interpolation of Escape character in variable?

Reply
Thread Tools

How to stop interpolation of Escape character in variable?

 
 
\Rob\
Guest
Posts: n/a
 
      02-22-2006
I have this code.....

<script language="JavaScript">
function getLogonUser() {

var u = '<% Response.Write(
Request.ServerVariables("LOGON_USER") ) %>'
alert( u )
}
</script>

......should return "MYDOMAIN\rob.test".....but the "\r" turns into a
Carriage return

Anybody know how to prevent this from happening?

Thanks


 
Reply With Quote
 
 
 
 
Darren Kopp
Guest
Posts: n/a
 
      02-22-2006
Request.ServerVariables("LOGON_USER").Replace('\r' , '') should work.

HTH,
Darren Kopp
http://blog.secudocs.com/

 
Reply With Quote
 
 
 
 
Daniel Kirsch
Guest
Posts: n/a
 
      02-22-2006
"Rob" wrote:
> I have this code.....
>
> <script language="JavaScript">
> function getLogonUser() {
>
> var u = '<% Response.Write(
> Request.ServerVariables("LOGON_USER") ) %>'
> alert( u )
> }
> </script>
>
> .....should return "MYDOMAIN\rob.test".....but the "\r" turns into a
> Carriage return
>
> Anybody know how to prevent this from happening?


You have to use a double backslash:

MYDOMAIN\\rob.test

Otherwise the character following the "\" will be interpreted as kind of
a special instruction character. That's the reason why path names have
double backslashes in many programming languages.

Daniel
 
Reply With Quote
 
Darren Kopp
Guest
Posts: n/a
 
      02-22-2006
Hahaha, he's right, i thought you meant \r at the end. Yea the \r in
\rob is needs to be \\rob.

-Darren

 
Reply With Quote
 
intrader
Guest
Posts: n/a
 
      02-22-2006
It would also work if Microsoft follows the lead (over 40 years) of Unix
and use '/' instead.


On Wed, 22 Feb 2006 10:09:22 -0800, Darren Kopp wrote:

> Request.ServerVariables("LOGON_USER").Replace('\r' , '') should work.
>
> HTH,
> Darren Kopp
> http://blog.secudocs.com/


 
Reply With Quote
 
\Rob\
Guest
Posts: n/a
 
      02-23-2006
Thanks, but I don't have the option to do that.....

<% Response.Write( Request.ServerVariables("LOGON_USER") ) %>

......is returning it to me.

"Darren Kopp" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) oups.com...
> Hahaha, he's right, i thought you meant \r at the end. Yea the \r in
> \rob is needs to be \\rob.
>
> -Darren
>



 
Reply With Quote
 
Darren Kopp
Guest
Posts: n/a
 
      02-23-2006
Is this classic ASP or ASP.NET?

If it's asp.net, the do
Response.Write(Request.ServerVariables("LOGON_USER ").Replace('\',
'\\'))

You could also just insert another \ at the IndexOf('\')

HTH,
Darren Kopp
http://blog.secudocs.com/

 
Reply With Quote
 
Bob Barrows [MVP]
Guest
Posts: n/a
 
      02-23-2006
"Rob" wrote:
> I have this code.....
>
> <script language="JavaScript">
> function getLogonUser() {
>
> var u = '<% Response.Write(
> Request.ServerVariables("LOGON_USER") ) %>'
> alert( u )
> }
> </script>
>
> .....should return "MYDOMAIN\rob.test".....but the "\r" turns into a
> Carriage return
>
> Anybody know how to prevent this from happening?
>

Double the backslash:

var u = '<% Response.Write(
Replace(Request.ServerVariables("LOGON_USER"),"\", "\\") ) %>'


--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.


 
Reply With Quote
 
Daniel Kirsch
Guest
Posts: n/a
 
      02-24-2006
Darren Kopp wrote:
> If it's asp.net, the do
> Response.Write(Request.ServerVariables("LOGON_USER ").Replace('\',
> '\\'))


Not sure, if asp.net will handle single backslashes, but in JavaScript
you need to escape them:

Replace('\\', '\\\\'))

> You could also just insert another \ at the IndexOf('\')


That should than be done for every "\" not only for the first one which
IndexOf('\') will probably return.

Daniel
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to read strings cantaining escape character from a file and useit as escape sequences? slomo Python 5 12-02-2007 11:39 AM
Assignment of var without escape/interpolation Bart Van der Donck Perl Misc 16 04-17-2006 10:29 AM
Force interpolation of single quoted character Scott Bass Perl Misc 11 05-29-2005 08:37 AM
Problem With String Containing JavaScript Escape Character Jeff S ASP .Net 12 11-10-2003 07:19 PM
single/double quote escape interpolation Simon Bunker Python 2 07-08-2003 02:15 AM



Advertisments