Click here to Skip to main content
13,452,705 members (55,126 online)
Rate this:
Please Sign up or sign in to vote.
Hi guys
I want to remove null byte from string in which i am searching for keywords.

here is the secnario:->

1) I created a dump file of my programs process memory using task-manager. and then I load dump file into the my other program and copied all content of dump file into string.

2) Now i want to search for keyword in this string. e.g "" but in string its is actually presented like "s y s t e m . s e c u r i t y . k e y" ( all spaces are actually null byte )

3) so if i remove null byte from it so that keyword look like "" in the string. and thus my program can search this keyword.
4) I tried to encode in Unicode and it does successfully but that is not what I want as it also change "key" that is placed next to my "" in a string, which is actually i am searching for.

I program all this in Visual C# .net

Thank you

Posted 28-Mar-10 7:57am
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

In C# and all other .NET languages text is stored in strings, and consists of characters, which are 16-bit quantities supporting a wide assortment of letters, digits and symbols. Those characters that do exist in the 7-bit ASCII set are represented by the same numeric value in 16-bit Unicode, yielding a low-byte holding the ASCII value and a high-byte of zero.

If you think you don't need Unicode for what you are after, then don't use strings to represent your data. Use byte arrays instead.

Rate this: bad
Please Sign up or sign in to vote.

Solution 2

string result = input.Replace("\0", string.Empty);

However, as you have already been told, using Unicode UTF16 is a bad idea. If you really need Unicode, you should use UTF8 instead.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web03-2016 | 2.8.180318.3 | Last Updated 29 Mar 2010
Copyright © CodeProject, 1999-2018
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100