比如:输入字符串2+45+435*34+(3*5)+4   输出2,+,45,+,435即把每个字符都输出来

解决方案 »

  1.   

    string str = "2+45+435*34+(3*5)+4";
                char[] num = new char[100];
                char[] other = new char[100];
                int i = 0;
                int j = 0;
                foreach (char ch in str)
                {
                    if (Char.IsNumber(ch))
                    {
                        num[i++] = ch;
                    }
                    else
                    {
                        other[j++] = ch;
                    }
                }
      

  2.   

    string str = "2+45+435*34+(3*5)+4";
                char[] num = new char[100];
                char[] other = new char[100];
                int i = 0;
                int j = 0;
                foreach (char ch in str)
                {
                    if (Char.IsNumber(ch))
                    {
                        num[i++] = ch;
                    }
                    else
                    {
                        other[j++] = ch;
                    }
                }
      

  3.   

            string text = "2+45+435*34+(3*5)+4";
           public void Disp()
            {
                for (int i = 0; i < text.Length; i++)
                {
                    //为了看清效果,这里分行输出
                    Console.WriteLine(text.Substring(i, 1));
                }
            }
    前面的接收字符串的逻辑我就不写了,那很简单.
      

  4.   

            private string GetResult(string express)
            {
                string result=string.Empty;
                string temp="";
                foreach (char c in express)
                {
                    if (char.IsDigit(c)) temp += c.ToString();
                    else
                    {
                        if (temp != "") result += temp + ",";
                        result += c.ToString() + ",";
                        temp = "";
                    }
                }
                if (temp != "") result += temp;
                return result.TrimEnd(",");
            }
      

  5.   

    List<char> chars = new List<char>();
    List<string> result = new List<string>();
    string str = "2+45+435*34+(3*5)+4"; 
     for(int i = 0;i < str.Length; i ++)
                { 
                    if (!Char.IsNumber(str[i])) 
                    { 
                        if(chars.Count > 0)
                        {
                            result.Add(new string(chars.ToArray()));
                            chars.Clear();
                        }
                        result.Add(str[i].ToString());
                    } 
                    else 
                    { 
                        chars.Add(str[i]); 
                    } 
                }按顺序输出result里面的item即可。
      

  6.   

            private string GetResult(string express)
            {
                string result=string.Empty;
                string temp="";
                foreach (char c in express)
                {
                    if (char.IsDigit(c)) temp += c.ToString();
                    else
                    {
                        if (temp != "") result += temp + ",";
                        result += c.ToString() + ",";
                        temp = "";
                    }
                }
                if (temp != "") result += temp;
                return result.TrimEnd(',');//上面有误,这里要换成单引。。
            }
      

  7.   

    2楼 534 也是char类型????
      

  8.   

    System.Text.RegularExpressions.Regex regexp = new System.Text.RegularExpressions.Regex(@"\d+|\D");
                System.Text.RegularExpressions.MatchCollection matchs =  regexp.Matches("2+45+435*34+(3*5)+4");            foreach (System.Text.RegularExpressions.Match match in matchs)
                {
                    System.Console.Write(match.Value+",");
                }