现有
<Config MachineType="2" Lang="0" OptimizedType="0" PLCFileName="\HardDisk2\MotionLCE\Basic.plc" FirmwareFileName="" IP3="0" IP4="10">
</Config>
需要用一个循环连续读取此项中所有Attribute的值,而不是一条条读取,情歌问大侠指点好方法。
------解决方案--------------------
try...
- C# code
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"; }
------解决方案--------------------
- C# code
/*---输出---Key: MachineTypeValue: 2====================Key: LangValue: 0====================Key: OptimizedTypeValue: 0====================Key: PLCFileNameValue: \HardDisk2\MotionLCE\Basic.plc====================Key: FirmwareFileNameValue: ====================Key: IP3Value: 0====================Key: IP4Value: 10====================*/