您的位置:首页 > 其它

使用正则表达式生成匹配数组

2008-02-22 13:57 288 查看
private List<Double> reg(string instr, string dw)

{

//生成list

List<Double> list = new List<Double>();

Regex regex = new Regex("(\\d+)(\\.(\\d+)?)?" + dw);

MatchCollection matchs = regex.Matches(instr);

foreach (Match match in matchs)

{

list.Add(Convert.ToDouble(match.Value.Substring(0, match.Value.IndexOf(dw))));

}

//将list的最大值和最小值放在最后和最前面的位置上;

int listCount = list.Count;

if (listCount <= 1)

return list;

else

{

Double max = -100.0, min = 100.0;

for (int i = 0; i <= list.Count - 1; i++)

{

if (i == 0)

{

max = min = list[0];

}

if (list[i] > max)

{

max = list[i];

}

if (list[i] < min)

{

min = list[i];

}

}

list[0] = min;

list[listCount - 1] = max;

}

return list;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: