![]() |
How to handle "\x"
Hi guys. In my system, I'm using javascript to grab current user who logged in to the system. So it will show the current user ID for example like "domain\john". My problem is if the user ID started with character "x" or "u", for example "domain\xia", system will show nothing meaning there is an error occured. Can anybody please help me on this? Thanks in advance.
|
You need to escape the backslash which otherwise interprets \x and \u as a hex or unicode number.
var str = "domain\\xia" var str = "domain\john" alert (str); // domainjohn var str = "domain\\john" alert (str); // domain\john var str = "domain\\xia" alert (str); // domain\xia But it is not a good idea to use a backslash as a delimiter. Javascript will interpret the backslash character as an 'escape' character to signal some special interpretation of the following character. Frustration - the first time you can't do it the second time. Desperation - the second time you can't do it the first time |
I only can put that double backslash if the user ID value is define in the javascript function itself. The problem is the value of the user ID is automatically get from funtion "<%= SPContext.Current.Web.CurrentUser.LoginName %>", so I can't put double slash in the user ID value. Any idea please...
|
As I say, Javascript interprets a backslash as a control character. Replace() does not work as \x is not two separate characters, but one control character. You must either ban user ids which start with u or x, or revise your server-side code to change the delimiter to something other than a backslash. Note that domain\john is rendered as domainjohn in Javascript as the backslash is ignored here.
|
| All times are GMT +1. The time now is 09:54 AM. |
Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.