Cerebrus
unread,Aug 20, 2009, 6:31:29 AM8/20/09Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting
The following code seems to work for me. Test it and let me know. I'm
not sure why you are padding the hex string.
---
static void Main(string[] args)
{
string EngToHex = StrToHex("Cerebrus");
string ArabToHex = StrToHex("مرحبا");
string HexToEng = HexToStr("43 65 72 65 62 72 75 73");
string HexToArab = HexToStr("645 631 62D 628 627");
}
private static string StrToHex(string input)
{
StringBuilder s = new StringBuilder();
foreach (char chr in input)
{
int val = Convert.ToInt32(chr);
s.AppendFormat("{0:X} ", val);
}
return s.ToString().Trim();
}
private static string HexToStr(string input)
{
StringBuilder s = new StringBuilder();
string[] hexVals = input.Split(' ');
foreach (string hexVal in hexVals)
{
int val = Convert.ToInt32(hexVal, 16);
char charVal = (char)val;
s.Append(charVal);
}
return s.ToString();
}
---