By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,671 Members | 1,413 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,671 IT Pros & Developers. It's quick & easy.

removing special characters

P: n/a
i'm reading from a database and found special character showing up as \0
or
�� when i serialize to xml.

trim does not work and using the string.Replace doesn't either.

how do i remove these?
Nov 13 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Mark Bosley <bo*********@hotmail.com> wrote:
i'm reading from a database and found special character showing up as \0
or
&#x0;&#x0; when i serialize to xml.

trim does not work and using the string.Replace doesn't either.

how do i remove these?


Trim should work just fine, as should string.Replace - could you give a
short but complete example of them not working? Here's one showing them
working:

using System;

public class Test
{
static void Main ()
{
string original = "hello\0 there\0\0\0";
string trimmed = original.Trim ('\0');
string replaced = original.Replace ("\0", "");

Console.WriteLine (original.Length);
Console.WriteLine (trimmed.Length);
Console.WriteLine (replaced.Length);
}
}

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet/
If replying to the group, please do not mail me too
Nov 13 '05 #2

P: n/a
On Thu, 10 Jul 2003 12:11:03 -0700, "Mark Bosley"
<bo*********@hotmail.com> wrote:
i'm reading from a database and found special character showing up as \0
or
&#x0;&#x0; when i serialize to xml.

trim does not work and using the string.Replace doesn't either.

how do i remove these?
My guess is that you are calling it like this:

stringvar.Trim("\0");

However, in C#, strings are immutable, so that call actually returns a
new string. Call it like this:

stringvar=stringvar.Trim("\0");

'Lib


Nov 13 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.