OK so I'm making a ASCII to HEX converter and it works fine, but when i insert line breaks it replaces them with this character -> Ú
ie
turns this
1
2
3
to this
1Ú2Ú3
Code under command buttons
private void asciiToHex_Click(object sender, EventArgs e)
{
HexConverter HexConvert =new HexConverter();
string sData=textBox1.Text;
textBox2.Text = HexConvert.StringToHexadecimal(sData);
}
private void hexToAscii_Click(object sender, EventArgs e)
{
HexConverter HexConvert = new HexConverter();
string sData = textBox1.Text;
textBox2.Text = HexConvert.HexadecimalToString(sData);
}
Code under HexConverter.cs
public class HexConverter
{
public string HexadecimalToString(string Data)
{
string Data1 = "";
string sData = "";
while (Data.Length > 0)
//first take two hex value using substring.
//then convert Hex value into ascii.
//then convert ascii value into character.
{
Data1 = System.Convert.ToChar(System.Convert.ToUInt32(Data.Substring(0, 2), 16)).ToString();
sData = sData + Data1;
Data = Data.Substring(2, Data.Length - 2);
}
return sData;
}
public string StringToHexadecimal(string Data)
{
//first take each charcter using substring.
//then convert character into ascii.
//then convert ascii value into Hex Format
string sValue;
string sHex = "";
foreach (char c in Data.ToCharArray())
{
sValue = String.Format("{0:X}", Convert.ToUInt32(c));
sHex = sHex + sValue;
}
return sHex;
}
}
Any Ideas?