Community Forums Archive

Go Back

Subject:Remove characters from region
Posted by: Kit
Date:1/19/2014 8:47:25 AM

I know how to replace a character: eg


public string CleanFilename(string szName)
{
szName = szName.Replace('!', '_');
szName = szName.Replace('?', '_');
szName = szName.Replace(':', '_');
szName = szName.Replace('\\', '_');
szName = szName.Replace('/', '_');
foreach (char ch in System.IO.Path.GetInvalidPathChars())
{
szName = szName.Replace(ch, '_');
}
return szName;
}


But how to remove a character, specifically characters that create errors in file names. Thanks


Subject:RE: Remove characters from region
Reply by: roblesinge
Date:1/19/2014 12:18:50 PM

The foreach loop you have is how I would do this. Is it not working for you?

Rob.

Subject:RE: Remove characters from region
Reply by: Kit
Date:1/19/2014 6:44:32 PM

Thanks for the reply. It is replacing characters. So for example, "What is this?" becomes "What is this_". I just want to remove the character. I tried:

szName = szName.Replace('?', '');


But Sound Forge complained about an empty character literal.

Subject:RE: Remove characters from region
Reply by: Kit
Date:1/19/2014 7:02:00 PM

I figured it out. I need:

szName = szName.Replace("?", ""); 

Subject:RE: Remove characters from region
Reply by: roblesinge
Date:1/20/2014 7:51:26 AM

Yeah, that will do it. I didn't understand what you were asking.

Rob.

Go Back