为什么中国坐标正反运算计算器字符串转化为float时候提示输入的的字符串格式不正确?
问题描述:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
namespace 坐标正反算
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private struct rowDdta
{
public double x, y; //A
public double X, Y; //B
public double D, a, R; //水平距离,坐标方位角;
}
List<rowDdta> Data = new List<rowDdta>();
private void button1_Click(object sender, EventArgs e)
{
string str;
string[] strs;
rowDdta rD = new rowDdta();
for (int i = 0; i < textBox1.Lines.Length; i++)
{
str = textBox1.Lines[i];
strs = str.Split(',');
rD.x = Convert.ToDouble(strs[0]);
rD.y = Convert.ToDouble(strs[1]);
rD.a = Convert.ToDouble(strs[2]);
rD.D = Convert.ToDouble(strs[3]);
rD.X = rD.x + rD.D * Math.Cos(rD.a);
rD.Y = rD.y + rD.D * Math.Sin(rD.a);
Data.Add(rD);
}
for (int i = 0; i < Data.Count; i++)
{
textBox2.Text = textBox2.Text + Data[i].X + "," + Data[i].Y + "\r\n";
}
}
答
加上
MessageBox.Show(strs[0]);
看看输出什么
应该有多余的空格或者非法的字符