Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Escape characters in a combobox

Status
Not open for further replies.

lappup

Programmer
Sep 3, 2001
3
0
0
EU
Hi All,

I have a combobox that is populated with a list of installed printers:


foreach (String strPrinter in PrinterSettings.InstalledPrinters)
{
cboPrinter.Items.Add(strPrinter);
}

this works fine and displays the printers installed on my machine, which is then stored to a mySQL db. The problem now is that when I come to delete the printer from the database table the cboPrinter.Text includes escape characters:

i.e \\share\printername in the combobox
becomes
\\\\share\\printername when the text is taken from combobox.text

Any ideas how to remove or get the litral string from the text.

Many thanks

Al
 
You can use the Replace function to do this, eg.

Code:
string sComboText, sPrinter;

sComboText= "\\\\share\\printername";

sPrinter= sComboText.Replace("\\","\");

Patrick
 
I had thought of this, but then I would also have to check for any other escape sequences. just wondered if there was a way of returning the literal string as displayed in the combobox.

Thanks for your time.

Al
 
Is this when you are debugging, or actually running the winForm?
 
This is when running in both debug and producion. I'm trying to use the text in a sql statement:

conDAL.deleteRecord("Printer","Delete from DBA.Printer where Printer_Name = '" + cboPrinterName.Text + "'");

This won't find the printer because ' \\\\share\\printername ' doesn't exist on the dbtable but ' \\share\printername ' does.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top