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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Parenthesis Expected error in ASP.NET! 1

Status
Not open for further replies.

z07924

IS-IT--Management
Feb 18, 2002
122
GB
OrigPath = OrigPath.Replace(Convert.ToChar("\"),Convert.ToChar("\\"));

I want to replace single backslash with double backslash.
Here I am getting error in the above line as given below.

1: ) expected
2: Invalid expression term ''
3: Newline in constant

I am getting these errors. Please help me out.I would highly appreciate any help.

Thanks.
 
does this help? i have to leave in a minute so i cant test it
Code:
OrigPath = OrigPath.Replace(Convert.ToChar("\\"),Convert.ToChar("\\\"));

ie an extra backslash in each place

i think (i'm pretty new to all this) that C# ignores the first backslash it finds (even inside a "....." string) unless it specifies a newline

eg "Brad Pitt \n" would mean "Brad Pitt" followed by a newline character

hope this helps/makes sense
 
It doesn't help me out. It is giving the same error.
I would highly appreciate any help.

Thanks.

 
Might try:

OrigPath = OrigPath.Replace("/","//")
 
Hi Z,

You got a couple problem here, first off you are using the ToChar function. A char in C# is a 1 character string so there will be an error in that function although you are not seeing it yet because of your other problem.

In C# a simple \ denotes a newline character so it must be escaped out. Therefore your correct code should be:

OrigPath = OrigPath.Replace("\\","\\\\");

Without the Convert.toChar functions.
 
Thanks a lot. It is working now. I had a meeting yseterday thats why I couldn't reply you immediately.
 
Dave,

why does it need four backslashes? i'm most probably being dim here (it being friday afternoon). does it take the first one to be a newline character, the second to be an ordinary backslash character, the third again newline, and the fourth again a normal backslash?
if you wanted to replace "\" with "\\\" would it be

OrigPath.Replace("\\", "\\\\\\")

??

Actually when i think about it that sort of makes sense. sort of... but i was expecting in z's case it would only need three backslashes....


thanks
 
That is what I was trying to say earlier, should have used "backslashes", but a ratio of "one" to "two" in the string replacement.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top