Is there a reason for this? I am asking because if you needed to use lots of empty chars then you get into the same situation as you would when you use lots of empty strings.
Edit: The reason for this usage was this:
myString.Replace ('c', '')
So remove all instances of 'c's from myString.
Not an answer to your question, but to denote a default
char
you can use justwhich is same as
char.MinValue
which in turn is same as\0
. One shouldn't use if for something like an empty string though.You can also rebuild your string character by character, excluding the characters that you want to get rid of.
Here's an extension method to do this:
It's not slick or fancy, but it works well.
Use like this:
I know this one is pretty old, but I encountered an issue recently with having to do multiple replacements to make a file name safe. First, in the latest .NET string.Replace function null is the equivalent to empty character. Having said that, what is missing from .Net is a simple replace all that will replace any character in an array with the desired character. Please feel free to reference the code below (runs in LinqPad for testing).
How about BOM, the magical character Microsoft adds to start of files (at least XML)?
if you want to elliminate the empty char in string the following will work, just convert to any datatype representation you want. thanks,
Doesn't answer your first question - but for the specific problem you had, you can just use strings instead of chars, right?:
There a reason you wouldn't want to do that?