Is there a way, where i can avoid the ‘\’ character from a string ?
//bit array
BitArray b1 = new BitArray(Encoding.ASCII.GetBytes("10101010"));
BitArray b2 = new BitArray(Encoding.ASCII.GetBytes("10101010"));
//Say i perform XOR operation on this
b1 = b1.Xor(b2);
//After the XOR oper the b1 var holds the result
//but i want the result to be displayed as 00000000
//So i convert the bitarray to a byte[] and then to string
byte[] bResult = ToByteArray(b1);
strOutput = Encoding.ASCII.GetString(bResult);
Output
The string strOutput is = "\0\0\0\0\0\0\0\0"
But the desired output is 00000000
where ToByteArray could be a simple method as this
public static byte[] ToByteArray(BitArray bits)
{
byte[] ret = new byte[bits.Length / 8];
bits.CopyTo(ret, 0);
return ret;
}
Alternative 1 : i can ignore the ‘\’ character using regular expressions or string.replace
But is there any other better way to handle such scenarios ?
You cant just manipulate values inside a binary row.Instead,as you’ve given alternatives,use regular expressions or string replace function to get your designated result set.
For example:
By calling an extra method to your code
EDIT:
I believe in your case normally my answer would work,
BUT
is also in ASCII character set(only in 0),that means you’re given the same string \0\0\0\0 .. replacing with backslash character (\)