473,396 Members | 2,030 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Strings and Escape Characters

I am storing a printer name in the registry. If its a networked printer, it
stores as so: \\server\printername.
When I pull that value in code, and throw it in a string, I get
\\\\server\\printername.

I get why this is happening, but I have a legacy dll that I need to pass
that value into. It does not like me passing the value that way. However,
if I hardcode the value \\Server\Printername and pass that in, its just fine
with it. I am unsure what language the dll is written in. Is there any way
to prevent C# from tacking on the escape sequences on the \'s ?
Apr 6 '07 #1
7 4218
Try prefixing the string with the @ sign, e.g. string PrinterName =
@"\\server\printer" ... It might help. Without seeing your code though, it's
difficult to say.

R

in article 69**********************************@microsoft.com, Rahvyn at
Ra****@discussions.microsoft.com wrote on 4/6/07 10:04 PM:
I am storing a printer name in the registry. If its a networked printer, it
stores as so: \\server\printername.
When I pull that value in code, and throw it in a string, I get
\\\\server\\printername.

I get why this is happening, but I have a legacy dll that I need to pass
that value into. It does not like me passing the value that way. However,
if I hardcode the value \\Server\Printername and pass that in, its just fine
with it. I am unsure what language the dll is written in. Is there any way
to prevent C# from tacking on the escape sequences on the \'s ?

Apr 6 '07 #2
To clarify a bit. I need the string to hold the actual value:
"\\Server\Printername". Is there a way to put a sing \ into a string?

"Rahvyn" wrote:
I am storing a printer name in the registry. If its a networked printer, it
stores as so: \\server\printername.
When I pull that value in code, and throw it in a string, I get
\\\\server\\printername.

I get why this is happening, but I have a legacy dll that I need to pass
that value into. It does not like me passing the value that way. However,
if I hardcode the value \\Server\Printername and pass that in, its just fine
with it. I am unsure what language the dll is written in. Is there any way
to prevent C# from tacking on the escape sequences on the \'s ?
Apr 6 '07 #3
Rahvyn,

The way that you see it in the debugger is just the interpretation of
the string, the string still has only two slashes before the server name,
and one slash to delimit the printer name. There isn't an actual extra
slash in your string, unless you are adding it yourself.

Hope this helps.

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Rahvyn" <Ra****@discussions.microsoft.comwrote in message
news:69**********************************@microsof t.com...
>I am storing a printer name in the registry. If its a networked printer,
it
stores as so: \\server\printername.
When I pull that value in code, and throw it in a string, I get
\\\\server\\printername.

I get why this is happening, but I have a legacy dll that I need to pass
that value into. It does not like me passing the value that way.
However,
if I hardcode the value \\Server\Printername and pass that in, its just
fine
with it. I am unsure what language the dll is written in. Is there any
way
to prevent C# from tacking on the escape sequences on the \'s ?

Apr 6 '07 #4
Well, I can send the value to the dll just fine, using the @ symbol. So this
call:

PrintDoc(@"\\Server\Printername", Reply);

works just fine whereas this one:

printer = regKey.GetValue("Printer").ToString();
PrintDoc(printer, Reply);

Does not work.

"Randolph Potter" wrote:
Try prefixing the string with the @ sign, e.g. string PrinterName =
@"\\server\printer" ... It might help. Without seeing your code though, it's
difficult to say.

R

in article 69**********************************@microsoft.com, Rahvyn at
Ra****@discussions.microsoft.com wrote on 4/6/07 10:04 PM:
I am storing a printer name in the registry. If its a networked printer, it
stores as so: \\server\printername.
When I pull that value in code, and throw it in a string, I get
\\\\server\\printername.

I get why this is happening, but I have a legacy dll that I need to pass
that value into. It does not like me passing the value that way. However,
if I hardcode the value \\Server\Printername and pass that in, its just fine
with it. I am unsure what language the dll is written in. Is there any way
to prevent C# from tacking on the escape sequences on the \'s ?


Apr 6 '07 #5
Nicholas;

I understand its just showing like that in the debugger. But for whatever
reason, when I try to pass to the function with a string variable, it fails,
but with a hardcoded value of @"\\Server\PrinterName".

This is the function declaration in the includes file for the dll:
int PrintThermalWithNamedPrinter(char *PrinterName, char *RequestBuffer,
char *ReplyBuffer, char *SavePath);

Would it make a difference to pass a character array? Will C accept that?

"Nicholas Paldino [.NET/C# MVP]" wrote:
Rahvyn,

The way that you see it in the debugger is just the interpretation of
the string, the string still has only two slashes before the server name,
and one slash to delimit the printer name. There isn't an actual extra
slash in your string, unless you are adding it yourself.

Hope this helps.

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Rahvyn" <Ra****@discussions.microsoft.comwrote in message
news:69**********************************@microsof t.com...
I am storing a printer name in the registry. If its a networked printer,
it
stores as so: \\server\printername.
When I pull that value in code, and throw it in a string, I get
\\\\server\\printername.

I get why this is happening, but I have a legacy dll that I need to pass
that value into. It does not like me passing the value that way.
However,
if I hardcode the value \\Server\Printername and pass that in, its just
fine
with it. I am unsure what language the dll is written in. Is there any
way
to prevent C# from tacking on the escape sequences on the \'s ?


Apr 6 '07 #6
Rahvyn,

Without seeing how you are declaring it for calling through the P/Invoke
layer, the signature in the header file will only give 1/2 of the needed
information.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Rahvyn" <Ra****@discussions.microsoft.comwrote in message
news:4E**********************************@microsof t.com...
Nicholas;

I understand its just showing like that in the debugger. But for whatever
reason, when I try to pass to the function with a string variable, it
fails,
but with a hardcoded value of @"\\Server\PrinterName".

This is the function declaration in the includes file for the dll:
int PrintThermalWithNamedPrinter(char *PrinterName, char *RequestBuffer,
char *ReplyBuffer, char *SavePath);

Would it make a difference to pass a character array? Will C accept that?

"Nicholas Paldino [.NET/C# MVP]" wrote:
>Rahvyn,

The way that you see it in the debugger is just the interpretation of
the string, the string still has only two slashes before the server name,
and one slash to delimit the printer name. There isn't an actual extra
slash in your string, unless you are adding it yourself.

Hope this helps.

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Rahvyn" <Ra****@discussions.microsoft.comwrote in message
news:69**********************************@microso ft.com...
>I am storing a printer name in the registry. If its a networked
printer,
it
stores as so: \\server\printername.
When I pull that value in code, and throw it in a string, I get
\\\\server\\printername.

I get why this is happening, but I have a legacy dll that I need to
pass
that value into. It does not like me passing the value that way.
However,
if I hardcode the value \\Server\Printername and pass that in, its
just
fine
with it. I am unsure what language the dll is written in. Is there
any
way
to prevent C# from tacking on the escape sequences on the \'s ?



Apr 6 '07 #7
Rahvyn <Ra****@discussions.microsoft.comwrote:
I am storing a printer name in the registry. If its a networked printer, it
stores as so: \\server\printername.
When I pull that value in code, and throw it in a string, I get
\\\\server\\printername.
Do you definitely get that value, or is that just how it's showing in
the debugger?

See http://pobox.com/~skeet/csharp/strings.html#debugger

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Apr 6 '07 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

16
by: Paul Prescod | last post by:
I skimmed the tutorial and something alarmed me. "Strings are a powerful data type in Prothon. Unlike many languages, they can be of unlimited size (constrained only by memory size) and can hold...
3
by: Rune Froysa | last post by:
Trying something like:: import xmlrpclib svr = xmlrpclib.Server("http://127.0.0.1:8000") svr.test("\x1btest") Failes on the server with:: xml.parsers.expat.ExpatError: not well-formed (invalid...
7
by: teachtiro | last post by:
Hi, 'C' says \ is the escape character to be used when characters are to be interpreted in an uncommon sense, e.g. \t usage in printf(), but for printing % through printf(), i have read that %%...
20
by: Trevor | last post by:
I have a couple of questions regarding C# strings. 1) Sometimes I see a string in someone else's code like: string foo = @"bar"; What does the '@' do for you? 2) Is there a performance...
2
by: Bob [BVP] | last post by:
I have an .cs file I need to compile with csc.exe for codebehind access (no VS.NET). Trouble is that my oledb connection needs to use a unc type path.. when I use the unc path in conn I get...
17
by: Carl Mercier | last post by:
Hi, Is it possible to use special characters like \n or \t in a VB.NET string, just like in C#? My guess is NO, but maybe there's something I don't know. If it's not possible, does anybody...
131
by: Lawrence D'Oliveiro | last post by:
The "escape" function in the "cgi" module escapes characters with special meanings in HTML. The ones that need escaping are '<', '&' and '"'. However, cgi.escape only escapes the quote character if...
7
by: Matthew Warren | last post by:
Hi, I would expect this to work, rawstring=r'some things\new things\some other things\' But it fails as the last backslash escapes the single quote. ...although writing this I think I...
5
by: David Mathog | last post by:
I'm looking at a program which stores perl scripts in an array. Each script is stored as a single entry in that array, and the whole set of them live in a single header file (escaped out the wazoo...
1
by: Joe Strout | last post by:
Wow, this was harder than I thought (at least for a rusty Pythoneer like myself). Here's my stab at an implementation. Remember, the goal is to add a "match" method to Template which works like...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.