Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#1.0 C#2.0 C#3.0 Visual-Studio , +
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 28-Mar-10 7:57am
harji17474
Rate this: bad
good
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.
 
Smile | :)
  Permalink  
Rate this: bad
good
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.
  Permalink  
v2

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



Advertise | Privacy | Mobile
Web04 | 2.8.140709.1 | Last Updated 29 Mar 2010
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid