日期:2014-05-20 浏览次数:20759 次
string test = @"<Config MachineType=""2"" Lang=""0"" OptimizedType=""0"" PLCFileName=""\HardDisk2\MotionLCE\Basic.plc"" FirmwareFileName="""" IP3=""0"" IP4=""10""> </Config>"; Regex reg = new Regex(@"(?<key>[^\s=]+)=""(?<value>[^""]*)"""); MatchCollection mc = reg.Matches(test); foreach (Match m in mc) { richTextBox2.Text += "Key: " + m.Groups["key"].Value + "\nValue: " + m.Groups["value"].Value + "\n====================\n"; }
------解决方案--------------------
/*---输出--- Key: MachineType Value: 2 ==================== Key: Lang Value: 0 ==================== Key: OptimizedType Value: 0 ==================== Key: PLCFileName Value: \HardDisk2\MotionLCE\Basic.plc ==================== Key: FirmwareFileName Value: ==================== Key: IP3 Value: 0 ==================== Key: IP4 Value: 10 ==================== */