Convert hex string to ansi string in C#
Basically, I've carved a jpeg file from the Windows 7 thumbcache using C#, and want to save it as a jpeg. The issue I'm having is that I only seem to be able to export the file as unicode/ascii, when it needs to be in ansi (I believe) in order to be properly recognised as an image file.
I realise this is quite a specific problem, but any thoughts would be appreciated.
Craig.
Status:
Open Feb 24, 2011 - 07:32 AM
windows, images, file, jpeg, data carving
2answers
Answers
Mar 25, 2011 - 03:37 PM
You can use this C# code to convert a hex string to ASCII:
private string HexString2Ascii(string hexString)
{
StringBuilder sb = new StringBuilder();
for (int i = 0; i <= hexString.Length - 2; i += 2)
{
sb.Append(Convert.ToString(Convert.ToChar(Int32.Parse(hexString.Substring(i, 2), System.Globalization.NumberStyles.HexNumber))));
}
return sb.ToString();
}
Mar 31, 2012 - 10:44 AM
The question looks to be abandoned by the user who asked it. If no action is taken within 2 days, a Quomon Moderator will consider closing the question and distributing the points.
The Quomon Team
Answer this question
Share Your Own Experience & Expertise
We look to ensure that every question is answered by the best people with relevant expertise and experience, the best answers include multiple perspectives. Do you have relevant expertise or experience to contribute your answer to any of these commonly asked questions?
Add New Comment