Click here to Skip to main content
15,891,431 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hii ..i am writing javascript & html in C# .
I have written a function in javascript and i am calling this .
This is the function


JavaScript
setTimeout("StartTyping('"+CharacterPos+"')",delay);


i needed to write this in c# with inverted commas.

I have tried but i am getting error in this line


This is how i tried

C#
string s=string.format("setTimeout("StartTyping('"+CharacterPos+"')",delay);");


Please help me.
Posted
Updated 12-Apr-10 0:00am
v2

How about writing this as

string s = string.format("setTimeout(\"StartTyping('{0}')\", {1});", CharacterPos, delay);

I hope this will work. :rose:
 
Share this answer
 
Sry its not working ...... It works only when there is a single,double inverted comma for characterPos .

setTimeout("StartTyping('"+CharacterPos+"')", delay);
 
Share this answer
 
nimishasurendran wrote:
Sry Abishek ,its not working ...... It works only when there is a single,double inverted comma for characterPos .
This is the HTML code
setTimeout("StartTyping('"+CharacterPos+"')", delay);
I need to write this in c#


But it was posted as a new question - I have moved it here so Abishek can (possibly) see it, and deleted the false question.
 
Share this answer
 
Abhishek Sur is right - look at what he said.

In C#, the double quote character delimits a string constant - it always starts and end with a double quote. So if you want to include a double quote in your string, you have to do one of two things:
1) Include an ESCAPE character with the double quote which C# interprest as saying "The following character is meant to be part of the string, and not to be taken as a string delimiter". That character is blackslash, and this was what Abhishek Sur told you to use.
If you wrote:
string s=string.format("setTimeout(\"StartTyping('"+CharacterPos+"')\",delay);");
and assuming CharacterPos had the value 17, the compiler will make s equal to:
setTimeout("StartTyping('17')",delay);

2) Insert a atsign character before your string starts, and use a pair of double quote characters whenever you want to include a double quote in your string:
string s=string.format(@"setTimeout(""StartTyping('"+CharacterPos+"')"",delay);");
and assuming CharacterPos had the value 17, the compiler will make s equal to:
setTimeout("StartTyping('17')",delay);


The first method is the most usual, but the second is helpful when entering web or folder addresses as it removes the special status of backslash.

Note though that if you view your strings in the debugger, it will insert the backslash characters for you. This can be confusing, when you first look at it.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900