how to remove hex characters in a string..

  • Thread starter Thread starter Tim Mackey
  • Start date Start date
T

Tim Mackey

Hi,
I have a c# string variable, but it contains some hex characters like 0x19, and when i try to send this to a web service, the deserializer throws an exception. this problem i'm not too interested in solving (but you can read about it on http://www.error-bank.com/[email protected]_Thread.aspx)

i actually want to remove these funny characters from the string. i don't know a whole lot about encoding ascii / unicode etc. the string is supposed to be html so any binary or hex chars can be discarded. does anyone know a good way of doing this?

many thanks in advance
tim mackey.


\\ email: tim at mackey dot ie //
\\ blog: http://tim.mackey.ie //
67d0ebfec70e8db3
 
Well, if you do a myString.IndexOf("0x") that will give you an index you can
use to chop out 4 characters with myString.Remove(index, 4);
 
I'm not sure what "hex characters" are... A Hex number is more than one
character, and any character can be expressed as a hex code...

Do you want to remove a range of characters from a string?
Use something like: string output = Regex.Replace(input, @"[\x00-\x20]",
"");

Niki

Hi,
I have a c# string variable, but it contains some hex characters like 0x19,
and when i try to send this to a web service, the deserializer throws an
exception. this problem i'm not too interested in solving (but you can read
about it on
http://www.error-bank.com/[email protected]_Thread.aspx)

i actually want to remove these funny characters from the string. i don't
know a whole lot about encoding ascii / unicode etc. the string is supposed
to be html so any binary or hex chars can be discarded. does anyone know a
good way of doing this?

many thanks in advance
tim mackey.


\\ email: tim at mackey dot ie //
\\ blog: http://tim.mackey.ie //
67d0ebfec70e8db3
 
Hi Niki,
my apologies for not being explicit about the wording, of course you are
correct.
thanks for your reply. i think i'll go with the regex solution, it's faster
and easy to code.
i have one small question, which i've search for an answer online but didn't
come up with anything...
will the range 00 to 20 cover all non-printable characters? it works for the
sample data i have but i'd like to know if it will cover everything. i say
'non-printable' because it seems that this type are the ones that are
causing problems. basically i don't want any hex numbers in my string at
all.

thanks again for your help.
tim.
 
please ignore my previous post.
i found out that the ascii tables were what i was looking for, and 0x20 is
the space character, which i wish to include. all the previous once are
non-text characters so they're the ones i wish to remove.

many thanks
tim
 
Back
Top