开发者

Escaping quotes in VB.NET (aspx.vb)

开发者 https://www.devze.com 2023-03-17 12:54 出处:网络
Hi all i have the following code <%= Replace(FindAndReplace(objDR.Item(\"LENTAB_NAME\") ),\"\'\",\"\\\'\") %>

Hi all i have the following code

<%= Replace(FindAndReplace(objDR.Item("LENTAB_NAME") ),"'","\'") %>

in this we are replacing the ' character with \', which is working fine. but when i tried to enter values like '"" then it is giving scripting error as

')' expected

i tried to replace this thing as Replace(string,"'"","\'"") but failed can you please give me the solution to this!

Actually this is the code snippet

FoldersArray[FoldersArray.length] = new FoldersListItmes("<%= objDR.Item("TAB_ID") %>","<%= Replace(FindAndReplace(objDR.Item("LENTAB_NAME") ),"'","\\'") %>","<%= Replace(FindAndReplace(objDR.Item("TAB_NAME") ),"'","\'") %>" ,"<%=intCnt %>" )

i am using server side tags inside javascript function..开发者_运维问答.

Thanks


I'd imagine that you have to escape your escape character as well, since \ has a special meaning when used inside strings.

So essentially use "\\'".


You could just escape the quotes (you need to escape your backslash, as @Steve Wang mentioned), but then other characters (line newlines) will mess you up.

If you're using a recent version of ASP.Net, you may want to use the HttpUtility.JavaScriptStringEncode to encode all of the necessary characters. Sadly, that appears to be quite new, in .Net 4.

(That MSDN page mentions URL encoding, but I'm fairly sure that's just because Microsoft assigns their most entry-level staff to MSDN documentation; the function has nothing to do with URL encoding.)

0

精彩评论

暂无评论...
验证码 换一张
取 消