split         ~

解决方案 »

  1.   


    double[] _double = Array.ConvertAll<string, double>(textbox.Value.Split(' '), dd => Convert.ToDouble(dd));
      

  2.   


    谢谢解答。如果数字在一行,例如:111   333    444,这句话可以很好的执行,但是如果数据分成两行,例如:
    111 333  444
    222 111 333
    那么就不行了,显示convert.toDouble(dd)出现错误。是否可以帮我看看,如何处理,谢谢。
      

  3.   


                int tepm;
                var _double = this.textBox1.Text.Replace("\r\n"," ").Split(' ').Where(aa => int.TryParse(aa, out tepm)).Select(bb => Convert.ToDouble(bb)).ToArray();
            }
      

  4.   


     string str = "12 34 56";
      string[] split = str.Split(' ');这最简单的 ,但这样会有一个问题  如果数字中有多个空格话就出现“空”值
      

  5.   


                int tepm;
                var _double = this.textBox1.Text.Replace("\r\n"," ").Split(' ').Where(aa => int.TryParse(aa, out tepm)).Select(bb => Convert.ToDouble(bb)).ToArray();
            }
    这位兄弟u011710947是高手,但是语句太长,对于我这种菜鸟来说,不太容易理解语句的执行逻辑,所以难以应用和修改啊!!不过还是非常感谢。我觉得基本结构可能是这样的:
    step1:将this.textbox1.text分解成字符串数组,例如arrayStr
    step2:然后将arrayStr转为数值型数组arrayDouble
    u011710947能不能多写几条语句,实现这个功能呢?谢谢啊!
      

  6.   


    这位兄弟u011710947是高手,但是语句太长,对于我这种菜鸟来说,不太容易理解语句的执行逻辑,所以难以应用和修改啊!!不过还是非常感谢。我觉得基本结构可能是这样的:
    step1:将this.textbox1.text分解成字符串数组,例如arrayStr
    step2:然后将arrayStr转为数值型数组arrayDouble
    u011710947能不能多写几条语句,实现这个功能呢?谢谢啊!
      

  7.   


    var _double = this.textBox1.Text.Replace("\r\n"," ").Split(' ').Where(aa => int.TryParse(aa, out tepm)).Select(bb => Convert.ToDouble(bb)).ToArray();等价于
                string txt = this.textBox1.Text.Replace("\r\n", " ");
                string[] strs = txt.Split(' ');
                IList<double> _list = new List<double>();
                for(int i=0;i<strs.Count();i++)
                {
                    double d=0;
                    if (double.TryParse(strs[i], out d))
                        _list.Add(d);
                }
                double[] _doubleArr = _list.ToArray();
    当然如果你客户端做了限制,保证输入的字符只有数字的话,可以直接            string txt2 = this.textBox1.Text.Replace("\r\n", " ");
                string[] strs2 = txt.Split(' ');
                double[] _double2 = new double[strs2.Count()];
                for (int i = 0; i < _double2.Count(); i++)
                {
                    _double2[i] = Convert.ToDouble(strs2[i]);
                }
      

  8.   


    var _double = this.textBox1.Text.Replace("\r\n"," ").Split(' ').Where(aa => int.TryParse(aa, out tepm)).Select(bb => Convert.ToDouble(bb)).ToArray();等价于
                string txt = this.textBox1.Text.Replace("\r\n", " ");
                string[] strs = txt.Split(' ');
                IList<double> _list = new List<double>();
                for(int i=0;i<strs.Count();i++)
                {
                    double d=0;
                    if (double.TryParse(strs[i], out d))
                        _list.Add(d);
                }
                double[] _doubleArr = _list.ToArray();
    当然如果你客户端做了限制,保证输入的字符只有数字的话,可以直接            string txt2 = this.textBox1.Text.Replace("\r\n", " ");
                string[] strs2 = txt.Split(' ');
                double[] _double2 = new double[strs2.Count()];
                for (int i = 0; i < _double2.Count(); i++)
                {
                    _double2[i] = Convert.ToDouble(strs2[i]);
                }

    var _double = this.textBox1.Text.Replace("\r\n"," ").Split(' ').Where(aa => int.TryParse(aa, out tepm)).Select(bb => Convert.ToDouble(bb)).ToArray();等价于
                string txt = this.textBox1.Text.Replace("\r\n", " ");
                string[] strs = txt.Split(' ');
                IList<double> _list = new List<double>();
                for(int i=0;i<strs.Count();i++)
                {
                    double d=0;
                    if (double.TryParse(strs[i], out d))
                        _list.Add(d);
                }
                double[] _doubleArr = _list.ToArray();
    当然如果你客户端做了限制,保证输入的字符只有数字的话,可以直接            string txt2 = this.textBox1.Text.Replace("\r\n", " ");
                string[] strs2 = txt.Split(' ');
                double[] _double2 = new double[strs2.Count()];
                for (int i = 0; i < _double2.Count(); i++)
                {
                    _double2[i] = Convert.ToDouble(strs2[i]);
                }
    非常感谢,我来学习一下你的代码。。