Wednesday, March 28, 2012

String.Replace() in .net 1.1 did not work!

Hi, guys,

The following source code in Page_Load() did not work:

string pathVal = "2006\";
pathVal.Replace("\\", "/");

I still had the value "2006\", not "2006/", the one I expected.

I then tried the second line as:

pathVal.Replace('\', '/');

still no luck.

Any ideas? Thanks.Replace probably returns a new string that you need to set a variable to.

"Andrew" <Andrew@.discussions.microsoft.com> wrote in message
news:74E97D68-79AC-47AB-B2D3-802DF9579D77@.microsoft.com...
> Hi, guys,
> The following source code in Page_Load() did not work:
> string pathVal = "2006\";
> pathVal.Replace("\\", "/");
> I still had the value "2006\", not "2006/", the one I expected.
> I then tried the second line as:
> pathVal.Replace('\', '/');
> still no luck.
> Any ideas? Thanks.
You need to get the value value returned by Replace function. It returns
stirng variable.
"Andrew" <Andrew@.discussions.microsoft.com> wrote in message
news:74E97D68-79AC-47AB-B2D3-802DF9579D77@.microsoft.com...
> Hi, guys,
> The following source code in Page_Load() did not work:
> string pathVal = "2006\";
> pathVal.Replace("\\", "/");
> I still had the value "2006\", not "2006/", the one I expected.
> I then tried the second line as:
> pathVal.Replace('\', '/');
> still no luck.
> Any ideas? Thanks.
String.Replace() returns a new String value. You can always set the
returned value to the original string.

0 comments:

Post a Comment