首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

一段字符串的的处置

2013-04-20 
一段字符串的的处理本帖最后由 ediyal 于 2013-04-17 10:31:08 编辑orderid20130412111023_siteid10000_

一段字符串的的处理
本帖最后由 ediyal 于 2013-04-17 10:31:08 编辑 orderid=20130412111023_siteid=10000_userid=10000_username=%E7%AB%9E%E5%BD%A9%E6%9E%97%E6%9E%97_origins=0_lotid=10208_ixcue=20130412_money=120_mttul=60_one=2_code=wxc|20130402001=12,20130402002=9|2*1_50;wxc|20130402001=3,20130402002=0|2*1_10

以上是字符串格式
总共有orderid
siteid
userid
username
origins
lotid
ixcue
money
mttul
one
code几个参数,=号后面的值就是其对应的值。
求思路把参数和值可以提取出来。
类似hash表或者dictionary一样的键值对(不要受我思想的局限)
字符串?C#
[解决办法]

void Main()
{
string str="orderid=20130412111023_siteid=10000_userid=10000_username=%E7%AB%9E%E5%BD%A9%E6%9E%97%E6%9E%97_origins=0_lotid=10208_ixcue=20130412_money=120_mttul=60_one=2_code=wxc
[解决办法]
20130402001=12,20130402002=9
[解决办法]
2*1_50;wxc
[解决办法]
20130402001=3,20130402002=0
[解决办法]
2*1_10";
Regex reg=new Regex(@"(?i)(^
[解决办法]
_)(?<key>[a-z]+)=(?<value>((?!_(?!\d+)).)+)");
foreach(Match m in reg.Matches(str))
{
  Console.WriteLine("{0}\t\t{1}",m.Groups["key"].Value,m.Groups["value"].Value);
}

/*
orderid20130412111023
siteid10000
userid10000
username%E7%AB%9E%E5%BD%A9%E6%9E%97%E6%9E%97
origins0
lotid10208
ixcue20130412
money120
mttul60
one2
codewxc
[解决办法]
20130402001=12,20130402002=9
[解决办法]
2*1_50;wxc
[解决办法]
20130402001=3,20130402002=0
[解决办法]
2*1_10
*/

}

热点排行