Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   C# (http://www.programmingforums.org/forum16.html)
-   -   Small C# Problem - quotation marks in string (http://www.programmingforums.org/showthread.php?t=13226)

teishu May 29th, 2007 11:31 AM

Small C# Problem - quotation marks in string
 
Hi, im having trouble with quotation marks in a string.. here is the code that is bugging me..

:

html.WriteLine("<img src=""images//" & file & """ />");

i need it to output the line as follows:

<img src="images/imagename.jpg" />

the imagename.jpg is define in the file string.

the errors are as follows:

:

Error    1    ) expected    C:\Documents and Settings\Jason\My Documents\Visual Studio 2005\Projects\Project01\Project01\Form1.cs    63    43    Project01

Error    2    ; expected    C:\Documents and Settings\Jason\My Documents\Visual Studio 2005\Projects\Project01\Project01\Form1.cs    63    65    Project01

Error    3    ; expected    C:\Documents and Settings\Jason\My Documents\Visual Studio 2005\Projects\Project01\Project01\Form1.cs    63    70    Project01

Error    4    Invalid expression term ')'    C:\Documents and Settings\Jason\My Documents\Visual Studio 2005\Projects\Project01\Project01\Form1.cs    63    70    Project01


thanks in advance...

Kezzer May 29th, 2007 11:36 AM

Use the escape sequence \" to display the quotation mark otherwise it will exit the string literal in the function argument.

html.WriteLine("<img src=\"images//\" & file & "\" />");

Or something along those lines.

teishu May 29th, 2007 12:04 PM

Quote:

Originally Posted by Kezzer (Post 128365)
Use the escape sequence \" to display the quotation mark otherwise it will exit the string literal in the function argument.

html.WriteLine("<img src=\"images//\" & file & "\" />");

Or something along those lines.

that seems to give me even more errors :S

ReggaetonKing May 29th, 2007 12:07 PM

Try this:
:

html.WriteLine("<img src=\"images//\"" + file + "\" />");

Kezzer May 29th, 2007 12:14 PM

Ah, one quotation mark off, didn't spot that *headache looms*

teishu May 29th, 2007 12:20 PM

Quote:

Originally Posted by reggaeton_king (Post 128368)
Try this:
:

html.WriteLine("<img src=\"images//\"" + file + "\" />");

cheers m8, seems to do the trick..
there were so many question marks i couldn't get my head round them all lol! :banana:

pegasus001 May 30th, 2007 8:52 AM

You can use the @ before the strign, if i am not mistaken like :
:

@"<img src=""images//" & file & "" />"
This tells the compiler to take the string as is, a preformatted string.

teishu May 30th, 2007 9:16 AM

Quote:

Originally Posted by pegasus001 (Post 128470)
You can use the @ before the strign, if i am not mistaken like :
:

@"<img src=""images//" & file & "" />"
This tells the compiler to take the string as is, a preformatted string.

ah cool, ill have to remember that. will come in handy.
thanks

Kezzer Jun 1st, 2007 7:27 AM

Quote:

Originally Posted by pegasus001 (Post 128470)
You can use the @ before the strign, if i am not mistaken like :
:

@"<img src=""images//" & file & "" />"
This tells the compiler to take the string as is, a preformatted string.

Odd how I never knew that. Handy tip though, I'm assuming the @ symbol acts as a compiler preprocessor and formats the string for you.

Cheers for the tip, pegasus.


All times are GMT -5. The time now is 2:50 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC