使用正则表达式生成匹配数组
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;
}
{
//生成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;
}
相关文章推荐
- 记录下两个正则表达式的使用(惰性匹配)
- asp.net(c#) 使用Rex正则来生成字符串数组的代码
- 详解python里使用正则表达式的全匹配功能
- 使用正则表达式匹配进行文件类名的更改并且去除注释
- 路径变量中使用正则表达式匹配
- 我的Android进阶之旅------>Android使用正则表达式匹配扫描指定目录下的所有媒体文件(音乐、图像、视频文件)
- nginx不使用正则表达式匹配
- 使用正则表达式匹配一个网页中的所有超级链接
- 关于一个使用正则表达式匹配来写的显示时间的方法
- 使用正则表达式匹配JS函数代码
- Python使用中文正则表达式匹配指定中文字符串的方法示例
- perl 自定义包/模块的使用(正则表达式匹配email地址和ip)
- 浅谈php正则表达式中的非贪婪模式匹配的使用
- python中使用正则表达式匹配出字符串中的数字
- 正则表达式中的匹配,替换,切割,获取,这四个使用时具体用哪一个,进行案例分析
- 第11章 使用正则表达式的模式匹配(二)
- Hive 正则表达式使用 与 匹配中文
- 使用正则表达式 。从一个字符串中找出数字,多次匹配。
- 使用正则表达式匹配字符串格式
- qt 中使用正则表达式去除匹配到的内容