Re: New Line Constant Error!

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Joakim Karlsson (jkarlsson_at_NOSPAMjkarlsson.com)
Date: 01/25/05


Date: Tue, 25 Jan 2005 21:08:44 +0100

Chakkaradeep wrote:
> Hi all,
>
> i have a string,
>
> str_old="E:\a\b\c.exe",
>
> and i want to change to
>
> str_new="E:\\a\\b\\c.exe".
>

This would work:

string str_old = @"E:\a\b\c.exe";
string str_new = str_old.Replace(@"\", @"\\");

> so now i use IndexOf() function to find the position of '\' , but it is
> throwing error that a new line constant is present.
>
> (i.e); int n=str_old.IndexOf('\'); //error here..new line constant

As you are using a character literal, the line should look like this:

int n = str_old.IndexOf('\\');

But as I stated earlier, you could just use String.Replace in this case.

Regards,
Joakim



Relevant Pages