有一长串字符串如下(是连起来的,没有换行之类的):想取EventName和AssetId的值“??2?”和49,该怎么取?EventName=??2?ZoneItem=32=zoneAreaId=18AssetPrimaryCategoryName=????EventId=1967089BatteryStatus=HIGHZoneId=32AssetName=??DateInMs=1263533172140NetworkId=000CCC7B35ECAssetSerialNumber=AssetDescription=513Date=15 Jan 10 1:26 PMAreaName=?? 1Y=-1136X=2121ZoneName=zoneAssetCategoryItems=24=????AssetCategoryNames=????AssetPrimaryCategoryId=24EventType=?????FullLocationPath=AisinoDemoCenter/?? -1/?? 1/zonePriority=HIGHAssetCategoryIds=24EventSpecId=58AreaMapId=5ShortLocationPath=?? 1/zoneAreaMapName=demo1AssetId=49

解决方案 »

  1.   

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Text.RegularExpressions;namespace ConsoleApplication11
    {
        class Program
        {
            static void Main(string[] args)
            {
                string str = @"EventName=??2?ZoneItem=32=zoneAreaId=18AssetPrimaryCategoryName=????EventId=1967089BatteryStatus=HIGHZoneId=32AssetName=??DateInMs=1263533172140NetworkId=000CCC7B35ECAssetSerialNumber=AssetDescription=513Date=15 Jan 10 1:26 PMAreaName=?? 1Y=-1136X=2121ZoneName=zoneAssetCategoryItems=24=????AssetCategoryNames=????AssetPrimaryCategoryId=24EventType=?????FullLocationPath=AisinoDemoCenter/?? -1/?? 1/zonePriority=HIGHAssetCategoryIds=24EventSpecId=58AreaMapId=5ShortLocationPath=?? 1/zoneAreaMapName=demo1AssetId=49";
                Regex reg = new Regex(@"EventName=(?<EventName>[\d\?]+).*?AssetId=(?<AssetId>[\d]+)"); 
                MatchCollection mc = reg.Matches(str);
                foreach (Match m in mc)
                {                Console.WriteLine("{0}", m.Groups["EventName"].Value);
                    Console.WriteLine("{0}", m.Groups["AssetId"].Value);
                   
                }        }
        }
    }
      

  2.   

    http://topic.csdn.net/u/20100115/14/4b6890e7-9d59-41e3-b62a-f135c175843b.html看这个