473,396 Members | 2,026 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

unrecognized escape sequence

can anyone tell me why this string throws an error:

strValues += "<tr><td><a href=\"\#\" onclick=\"javascript:" + strTextBox +
".value='" + drRDK[strValue].ToString().Replace("\\", "\\\\").Replace("'",
"\\'").Replace('"', '""') + "';" + strDiv + ".style.visibility='hidden';" +
strDiv + ".innerHTML='';\">" + strOutput + "</a></td></tr>\n\r";

my code edit colors it correctly but it throws an error
please help
Nov 17 '05 #1
4 5245
Abraham Luna <ab*@rdk.com> wrote:
can anyone tell me why this string throws an error:

strValues += "<tr><td><a href=\"\#\" onclick=\"javascript:" + strTextBox +
".value='" + drRDK[strValue].ToString().Replace("\\", "\\\\").Replace("'",
"\\'").Replace('"', '""') + "';" + strDiv + ".style.visibility='hidden';" +
strDiv + ".innerHTML='';\">" + strOutput + "</a></td></tr>\n\r";

my code edit colors it correctly but it throws an error
please help


# doesn't need escaping - where you've got \#, that's an illegal escape
code.

Note that your code would be *much* easiest to read if you'd break each
bit onto a different line, even if you still have it within the same
statement. For example:

strValues += "<tr><td><a href=\"\#\" onclick=\"javascript:" +
strTextBox +
".value='" +
drRDK[strValue].ToString()
.Replace("\\", "\\\\")
.Replace("'", "\\'")
.Replace('"', '""') +
"';" +
strDiv +
".style.visibility='hidden';" +
strDiv +
".innerHTML='';\">" +
strOutput +
"</a></td></tr>\n\r";

Using a StringBuilder and breaking it up further would almost certainly
add more to the readability too - *and* make it easier to find out
where the error is when you get one.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 17 '05 #2
thank you for the answer. this is what i came up with and it finally works:

string varValue = drRDK[strValue].ToString().Replace("\\",
"\\\\").Replace("'", "\\'").Replace(@"""", @"""""");
strValues += @"<tr><td><a href=""#"" onclick=""javascript:" + strTextBox
+ ".value='" + varValue + "';" + strDiv + ".style.visibility='hidden';" +
strDiv + @".innerHTML='';"">" + strOutput + "</a></td></tr>" + "\n\r";

do u know anything about html? cause that code above works :), but the
javascript it produces sometimes doesn't. this is something the above
generates that doesn't work:

<tr><td><a href="#"
onclick="javascript:ctl00_ctl00_cphMainContent_cph Customers_tbName.value='DOUBLE
""H"" ENTERPRISES
INC';divOfNames.style.visibility='hidden';divOfNam es.innerHTML='';">14585 -
DOUBLE "H" ENTERPRISES INC</a></td></tr>

how can i get the ""H"" to work right. thank you
"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
Abraham Luna <ab*@rdk.com> wrote:
can anyone tell me why this string throws an error:

strValues += "<tr><td><a href=\"\#\" onclick=\"javascript:" + strTextBox
+
".value='" + drRDK[strValue].ToString().Replace("\\",
"\\\\").Replace("'",
"\\'").Replace('"', '""') + "';" + strDiv + ".style.visibility='hidden';"
+
strDiv + ".innerHTML='';\">" + strOutput + "</a></td></tr>\n\r";

my code edit colors it correctly but it throws an error
please help


# doesn't need escaping - where you've got \#, that's an illegal escape
code.

Note that your code would be *much* easiest to read if you'd break each
bit onto a different line, even if you still have it within the same
statement. For example:

strValues += "<tr><td><a href=\"\#\" onclick=\"javascript:" +
strTextBox +
".value='" +
drRDK[strValue].ToString()
.Replace("\\", "\\\\")
.Replace("'", "\\'")
.Replace('"', '""') +
"';" +
strDiv +
".style.visibility='hidden';" +
strDiv +
".innerHTML='';\">" +
strOutput +
"</a></td></tr>\n\r";

Using a StringBuilder and breaking it up further would almost certainly
add more to the readability too - *and* make it easier to find out
where the error is when you get one.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 17 '05 #3
strValues += "<tr><td><a href=\"#\" onclick=\"javascript:" + strTextBox +
".value='" + drRDK[strValue].ToString().Replace("\\", "\\\\").Replace("'",
"\\'").Replace("\"", "\"\"") + "';" + strDiv + ".style.visibility='hidden';"
+ strDiv + ".innerHTML='';\">" + strOutput + "</a></td></tr>\n\r";

Escape sequence fixed. I would suggest using StringBuilder for this.

"Abraham Luna" wrote:
can anyone tell me why this string throws an error:

strValues += "<tr><td><a href=\"\#\" onclick=\"javascript:" + strTextBox +
".value='" + drRDK[strValue].ToString().Replace("\\", "\\\\").Replace("'",
"\\'").Replace('"', '""') + "';" + strDiv + ".style.visibility='hidden';" +
strDiv + ".innerHTML='';\">" + strOutput + "</a></td></tr>\n\r";

my code edit colors it correctly but it throws an error
please help

Nov 17 '05 #4
Abraham Luna <ab*@rdk.com> wrote:
thank you for the answer. this is what i came up with and it finally works:

string varValue = drRDK[strValue].ToString().Replace("\\",
"\\\\").Replace("'", "\\'").Replace(@"""", @"""""");
strValues += @"<tr><td><a href=""#"" onclick=""javascript:" + strTextBox
+ ".value='" + varValue + "';" + strDiv + ".style.visibility='hidden';" +
strDiv + @".innerHTML='';"">" + strOutput + "</a></td></tr>" + "\n\r";
It may work, but I certainly wouldn't want to be the one to debug it.
Why have it as one nasty big block when you can split it up nicely?
do u know anything about html? cause that code above works :), but the
javascript it produces sometimes doesn't. this is something the above
generates that doesn't work:

<tr><td><a href="#"
onclick="javascript:ctl00_ctl00_cphMainContent_cph Customers_tbName.value='DOUBLE
""H"" ENTERPRISES
INC';divOfNames.style.visibility='hidden';divOfNam es.innerHTML='';">14585 -
DOUBLE "H" ENTERPRISES INC</a></td></tr>

how can i get the ""H"" to work right. thank you


I suspect you want \"H\" in the JavaScript - but the right way to test
this is to edit it in a text file. Get it right, and *then* make your
C# code generate it.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 17 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Joe | last post by:
I'm using Python 2.4 on Windows XP SP2. I'm trying to receive a command line argument that is a newline (\n) Here is the command line to use sample.py "\n" Here is a sample.py script
14
by: Jon Maz | last post by:
Hi, I have been getting hopelessly confused with escaping escape characters in JScript! All I want to do is write a simple funtion: function DoubleUpBackSlash(inputString) { ??????? }
1
by: PK9 | last post by:
I'm trying to validate input from a textbox in the code-behind of my page. I don't want to use any validator controls for this, I'd like to do it all in the code behind. However, I'm getting an...
7
by: N U | last post by:
How to program your own escape sequence using basic functions available in C?
7
by: teachtiro | last post by:
Hi, 'C' says \ is the escape character to be used when characters are to be interpreted in an uncommon sense, e.g. \t usage in printf(), but for printing % through printf(), i have read that %%...
2
by: junky_fellow | last post by:
N869 " Each of these escape sequences shall produce a unique implementation-defined value which can be stored in a single char object. The external representations in a text file need not be...
2
by: Christopher Ireland | last post by:
Hi -- Any ideas on this one please ... The following code works as expected: private void Form1_Load(object sender, System.EventArgs e) { string text = "The quick brown"+ " FOX " +"jumps over...
6
by: sloan | last post by:
I have a fairly simple RegEx code below. I am given a file name, (which I don't control) , and need to change a folder name in it. The code below is choking on the filename not being...
5
by: vlsidesign | last post by:
The printf function returns "warning: unknown escape sequence: \040" for a backslash-space combination. If the ascii decimal number for space is 32 and the backslash is 92, why this particular...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.