Click here to Skip to main content
15,867,977 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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 "system.security.key" 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 "system.security.key" 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 "system.security.key" in a string, which is actually i am searching for.

I program all this in Visual C# .net

Thank you

Harsimran
Posted

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.

:)
 
Share this answer
 
C#
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.
 
Share this answer
 
v2

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900