好的,所以我正在制作一个 ASCII 到 HEX 转换器,它工作正常,但是当我插入换行符时,它会用这个字符替换它们 -> Ú
即
转这个
1
2
3
对此
1Ú2Ú3
命令按钮下的代码
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);
}
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;
}
}
有任何想法吗?