string str = {"Items":[{"Power":"402 W"},{"DailyYield":"5.3 kWh"},{"TotalYield":"8353.52 kWh"}]};
string[] para1 = str.split("W");//大写的W
string result = "";
if(para1 != null && para1.length > 0)
{
    for(int i = 0;i < para1.length;i ++)
    {
        string[] para2= para1[i].split("\"");
        if(para2 != null && para2.length > 0)
        {
            result += para2[para2.length - 1].replace("k","") + "#";
        }
    }
    result = result.subString(0,result.length - 1);
}
我是这样来写的,最后的result和你要的结果一样。不知道能不能帮到你忙。

解决方案 »

  1.   

    using System.Text.RegularExpressionRegex r=new Regex("([\\d]*) ¦([\\d]*\.[\\d]*)");
    string res=null;
    Match m;m=r.Match(sourcestring);while(m.Success){
    res=m.Value+"#";
    m=r.NextMatch;
    }
      

  2.   

    用正则嘛,多方便的using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Text.RegularExpressions;namespace ConsoleApplication1
    {
        class Program
        {
            static void Main(string[] args)
            {
                string str = "{\"Items\":[{\"Power\":\"402 W\"},{\"DailyYield\":\"5.3 kWh\"},{\"TotalYield\":\"8353.52 kWh\"}]}";
                var reg = new Regex(@"\d+(?:\.\d+)?");
                string s = "";
                Match ret = reg.Match(str);
                while (ret.Success)
                {
                    s += ret.Value + "#";
                    ret = ret.NextMatch();
                }
                s = s.Remove(s.Length - 1);
                Console.WriteLine(s);
                Console.Read();
            }
        }
    }
      

  3.   

    用正则嘛,多方便的using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Text.RegularExpressions;namespace ConsoleApplication1
    {
        class Program
        {
            static void Main(string[] args)
            {
                string str = "{\"Items\":[{\"Power\":\"402 W\"},{\"DailyYield\":\"5.3 kWh\"},{\"TotalYield\":\"8353.52 kWh\"}]}";
                var reg = new Regex(@"\d+(?:\.\d+)?");
                string s = "";
                Match ret = reg.Match(str);
                while (ret.Success)
                {
                    s += ret.Value + "#";
                    ret = ret.NextMatch();
                }
                s = s.Remove(s.Length - 1);
                Console.WriteLine(s);
                Console.Read();
            }
        }
    }