Imbedded doublequotes in string

Hey,

I;ve been screwing around with this for an hour and finally decided to ask you all. I am trying to build a javascript array

scriptstr = @"<script language=""javascript""> var evArray = [";
bool first = true;
while(oDr.Read())
{
      if (first) first = false;
      else scriptstr += ",";
      scriptstr += @"["";
      scriptstr += oDr["companyname"].ToString();
      scriptstr += @"","";
      scriptstr += oDr["codename"].ToString();
      scriptstr += @"","";
      scriptstr += oDr["amendnum"].ToString();
      scriptstr += @"","";
      scriptstr += oDr["waivernum"].ToString();
      scriptstr += @"","";
      scriptstr += oDr["duedate"].ToString();
      scriptstr += @""]";
}

I thought that with a literal string, using two double quotes was the way to get a double quote in the string. But the compiler does not like it at all!

Where am I going wrong?

Thanks
RichardFoxAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
eternal_21Connect With a Mentor Commented:
You are forgetting to put the whole string in quotes...  So if you want add the string:

  ","

you would code it as:

  @""","""

  or

  "\",\""
0
 
eternal_21Commented:
I think this is what you meant to do:

  scriptstr = @"<script language=""javascript""> var evArray = [";
  bool first = true;
  while(oDr.Read())
  {
    if (first) first = false;
    else scriptstr += ",";
    scriptstr += @"[""";
    scriptstr += oDr["companyname"].ToString();
    scriptstr += @""",""";
    scriptstr += oDr["codename"].ToString();
    scriptstr += @""",""";
    scriptstr += oDr["amendnum"].ToString();
    scriptstr += @""",""";
    scriptstr += oDr["waivernum"].ToString();
    scriptstr += @""",""";
    scriptstr += oDr["duedate"].ToString();
    scriptstr += @"""]";
  }
0
 
eternal_21Commented:
Did that help you RichardFox?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.