本帖最后由 xuri422 于 2011-05-13 22:48:33 编辑

解决方案 »

  1.   

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;namespace ConsoleApplication1
    {
        class Program
        {
            static void Main(string[] args)
            {
                double[] n = new double[100];
                int i = 0;
                string a = "123+32-59+1*44-222/111";
                char[] m = { '+', ' ', '-', '*', '/' };
                foreach (string r in a.Split(m))
                {
                    n[i] = Convert.ToDouble(r);
                    
                    i++;            }            char[] p = new char[100];
                for (int j = 0; j < a.Length; j++)
                {
                    if ((a[j] == '+') || (a[j] == '-') || (a[j] == '*') || (a[j] == '/'))
                        p[j] = a[j];
                  
                }
            
              
            }  
        }
    }
      

  2.   

    调用字符串的一个split()方法;
    你的 str="123+32-59+1*44-222/111";
    则拆分后的存在字符数组中 string [] str1=str.split(new char []{‘+’,‘-’,‘*’,‘-’,‘/’});
     
      

  3.   


    弄了一个用正则来匹配的,比较容易!
    string str = "123+32-59+1*44-222/111";            List<double> list = new List<double>();
                foreach(Match num in Regex.Matches(str,@"\d+"))
                    list.Add(double.Parse(num.Value));            double[] nums = list.ToArray();            List<char> chList = new List<char>();            foreach( Match l in Regex.Matches(str,@"[-+*/]"))
                    chList.Add(char.Parse(l.Value));            char[] ch = chList.ToArray();
      

  4.   


                string s = "123.2+32.5-59.7+1*44-222/111";
                List<double> numList = new List<double>();            char[] operators;
                double[] num;            operators = Regex.Replace(s, @"[\d]+(\.[\d]+)?", m => { numList.Add(Convert.ToDouble(m.Value)); return string.Empty; }).ToCharArray();
                num = numList.ToArray();
      

  5.   

    稍微修改下,可以把输入中可能有的空格也过滤掉            string s = "123.2 + 32.5 - 59.7 + 1*44 - 222 / 111";
                List<double> numList = new List<double>();            char[] operators;
                double[] num;            operators = Regex.Replace(s, @"[\d]+(\.[\d]+)?", m => { numList.Add(Convert.ToDouble(m.Value)); return string.Empty; }).Replace(" ",string.Empty).ToCharArray();
                num = numList.ToArray();
      

  6.   

    string str = "123+32-59+1*44-222/111";List<float> floatarray=new List<float>();   //浮点数组
    List<String> stringarray=new List<String>();  //字符串数组string tempstr="";
    int StartIndex=0;
    int EndIndex=0; 
    bool isnum=true;
    for(int i=0;i<str.length;i++)
    {
        EndIndex=i;
        if(Char.IsNumber(str[i]) ^ isnum)
        {
           tempstr=str.Substring(StartIndex,EndIndex-StartIndex);
           if(isnum)
           {
              floatarray.Add(float.Pharse(tempstr));
              isnum=false;
           }
           else
           {
              stringarray.Add(tempstr);
              isnum=true;
           }
           StartIndex=i;
        }
    }//别忘了最后还有一个
    tempstr=str.Substring(StartIndex,EndIndex-StartIndex+1);
    if(isnum)
    {
      floatarray.Add(float.Pharse(tempstr));
    }
    else
    {
      stringarray.Add(tempstr)
    }//这样应该就能分开了。
    //你没输入的运算符号不会被多余保存。
    //在回复里现写的,没经过验证,仅供参考。hoho~~~
      

  7.   

    我打字好慢啊,没想到已经回复了这么多。忘了考虑小数点了。
    其中的 if(Char.IsNumber(str[i]) ^ isnum)考虑改成
    if((Char.IsNumber(str[i]) ||str[i]=='.') ^ isnum)