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 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记