string error

  • Thread starter Thread starter Tiago Costa
  • Start date Start date
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'"";
 
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
 
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'""";
 
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.
 
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'"";
 
Back
Top