weixin_44143970 2018-12-19 16:32 采纳率: 0%
浏览 734

C#中从TXT中读取数据时显示字符串格式不正确怎么解决

获取数据代码如下:
private void 获取数据_Click(object sender, EventArgs e)
{
INput put = new INput();
put.Input(textBox1, textBox2, textBox3,textBox4,textBox5, textBox6, textBox7, textBox8, textBox9, textBox10, textBox11, textBox12, textBox13, textBox14, textBox15, textBox16, textBox17);
}
class INput
{
public void Input(TextBox textbox1, TextBox textbox2, TextBox textbox3, TextBox textbox4, TextBox textbox5, TextBox textbox6, TextBox textbox7, TextBox textbox8, TextBox textbox9, TextBox textbox10, TextBox textbox11, TextBox textbox12, TextBox textbox13, TextBox textbox14, TextBox textbox15, TextBox textbox16, TextBox textbox17)
{
double x1, x2, y1, y2, f;
double o1, o2, p1, p2, q1, q2;
double Xs1, Xs2, Ys1, Ys2, Zs1, Zs2;
OpenFileDialog openFileDialog1 = new OpenFileDialog();
openFileDialog1.ShowDialog();
string MyFileName = openFileDialog1.FileName;
if (MyFileName.Trim() == "")
return;
StreamReader sr = null;
sr = new StreamReader(MyFileName, System.Text.Encoding.Default);
Xs1 = double.Parse(sr.ReadLine());
Ys1 = double.Parse(sr.ReadLine());
Zs1 = double.Parse(sr.ReadLine());
o1 = double.Parse(sr.ReadLine());
p1 = double.Parse(sr.ReadLine());
q1 = double.Parse(sr.ReadLine());
Xs2 = double.Parse(sr.ReadLine());
Ys2 = double.Parse(sr.ReadLine());
Zs2 = double.Parse(sr.ReadLine());
o2 = double.Parse(sr.ReadLine());
p2 = double.Parse(sr.ReadLine());
q2 = double.Parse(sr.ReadLine());
x1 = double.Parse(sr.ReadLine());
y1 = double.Parse(sr.ReadLine());
x2 = double.Parse(sr.ReadLine());
y2 = double.Parse(sr.ReadLine());
f = double.Parse(sr.ReadLine());
textbox1.Text = Xs1.ToString("0.000000");
textbox2.Text = Ys1.ToString("0.000000");
textbox3.Text = Zs1.ToString("0.000000");
textbox4.Text = o1.ToString("0.000000");
textbox5.Text = p1.ToString("0.000000");
textbox6.Text = q1.ToString("0.000000");
textbox7.Text = Xs2.ToString("0.000000");
textbox8.Text = Ys2.ToString("0.000000");
textbox9.Text = Zs2.ToString("0.000000");
textbox10.Text = o2.ToString("0.000000");
textbox11.Text = p2.ToString("0.000000");
textbox12.Text = q2.ToString("0.000000");
textbox13.Text = x1.ToString("0.000000");
textbox14.Text = y1.ToString("0.000000");
textbox15.Text = x2.ToString("0.000000");
textbox16.Text = y2.ToString("0.000000");
textbox17.Text = f.ToString("0.000000");
}

    }
  • 写回答

1条回答 默认 最新

  • qq_34277516 2018-12-19 09:36
    关注

    需要转编码,
    string str1 = "aaa";
    byte[] bt = Encoding.UTF8.GetBytes(str1);
    string str2 = Encoding.Default.GetString(bt);
    //Encoding下有不同的编码方式 试一下就知道了。

    评论

报告相同问题?

悬赏问题

  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 关于#python#的问题:自动化测试
  • ¥20 问题请教!vue项目关于Nginx配置nonce安全策略的问题