tags:

views:

379

answers:

6

Why do none of these seem to work?

String.Replace("/", "_");
String.Replace("//", "_");
String.Replace(((char)47).ToString(), "_");

The string named "FileName" still says "MyFile 06/06/09"

+22  A: 

Are you assigning the FileName.Replace to something? It returns the new FileName, it doesn't actually change it.

string fileName = FileName.Replace("//", "");
Brandon
+10  A: 

You probably want to do this:

FileName = FileName.Replace("//", "")...
Cristian Libardo
+5  A: 

Try this:

FileName = FileName.Replace( "/", "_" );
Kieveli
+1  A: 
Filename = FileName.Replace("//", ""); 
Filename = FileName.Replace("/", ""); 
Filename = FileName.Replace(((char)47).ToString(), "_");
TheTXI
+4  A: 

If that is your actual code then you need to actually assign it back to the value as in...

FileName = FileName.Replace("//", ""); 
FileName = FileName.Replace("/", ""); 
FileName = FileName.Replace(((char)47).ToString(), "_");
Hugoware
+1  A: 

One more thing I'll add is to check your quote characters...if you paste from Word then you'll end up with the wrong characters. Of course, you'll get a compile-time error if that's the case...

Steve J