我正在尝试为大量十六进制数字制作一个十六进制到十进制的转换器。
{
textBox1.Text = textBox1.Text.Replace("-", "");
textBox1.Text = textBox1.Text.Replace(" ", "");
if (textBox1.TextLength > 0)
{
textBox2.Text = Int32.Parse(textBox1.Text, System.Globalization.NumberStyles.HexNumber).ToString();
}
textBox3.Text = textBox2.Text.ToString().Replace(Environment.NewLine, ", ");
}
在单行上工作得很好。尝试转换多行
时出错系统。FormatException:输入字符串格式不正确。
如果您使用的是多行文本框,请尝试替换其值的换行字符,如下所示:
textBox1.Text = textBox1.Text.Replace("rn", ""); // For Windows
textBox1.Text = textBox1.Text.Replace("n", ""); // For Unix/Linux