string error

T

Tiago Costa

I have a string that need to have the " char inside, but this give me an
error: end of the sring, how can i make the " a char of the string?

string comando = "OSQL -Usa -Psa -n -Q "BACKUP DATABASE Rendas TO DISK =
'c:\Rendas.dat_bak'"";
 
A

Arild Bakken

Use the escape character:

string commando = "OSQL -Usa -Psa -n -Q \"BACKUP DATABASE Rendas TO DISK =
'c:\\Rendas.dat_bak'\"";

or prefix with @ character:

string comando = @"OSQL -Usa -Psa -n -Q "BACKUP DATABASE Rendas TO DISK =
'c:\Rendas.dat_bal'"";

Arild
 
D

Daniel Bass

Prefixing with the @ would mean you'd need to double up on the quotes...

string comando = @"OSQL -Usa -Psa -n -Q ""BACKUP DATABASE Rendas TO DISK =
'c:\Rendas.dat_bal'""";
 
M

Morten Wennevik

or prefix with @ character:

string comando = @"OSQL -Usa -Psa -n -Q "BACKUP DATABASE Rendas TO DISK =
'c:\Rendas.dat_bal'"";

No, @ means ignore escape characters, meaning \ is treated as a regular character.
 
S

Shiva

Escape embedded " (double-quote) characters using '\'.

string comando = "OSQL -Usa -Psa -n -Q \"BACKUP DATABASE Rendas TO DISK =
'c:\Rendas.dat_bak'\"";
I have a string that need to have the " char inside, but this give me an
error: end of the sring, how can i make the " a char of the string?

string comando = "OSQL -Usa -Psa -n -Q "BACKUP DATABASE Rendas TO DISK =
'c:\Rendas.dat_bak'"";
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top