问题描述
请问,就是数组元素中有:例如:dfds_01、weds_02、adwews_03、desktop、folder、adsew._04。怎样把这里的desktop、folder这些不相关的去掉呢
解决方案
本帖最后由 zuiyizhilian 于 2012-03-14 06:05:07 编辑
解决方案二:
怎样算相关
解决方案三:
varlist=newstring[]{"dfds_01","weds_02","adwews_03","desktop","folder","adsew._04"};varfilter=newstring[]{"desktop","folder"};varresult=list.Except(filter);
解决方案四:
数组支持一个委托,用拉姆达表达式过滤.
解决方案五:
引用1楼xiaoshenyi2的回复:
怎样算相关
难道是要有_和数字
解决方案六:
二楼的varlist=newstring[]{"dfds_01","weds_02","adwews_03","desktop","folder","adsew._04"};varfilter=newstring[]{"desktop","folder"};varresult=list.Except(filter);固然好理解,而且简单,但这个数组里只知道"dfds_01","weds_02","adwews_03","adsew._04",而其它的字符串不知道什么格式的,我怎样才能把这些"dfds_01","weds_02","adwews_03","adsew._04",挑选出来比如,我这些都是文件名,而我只要"dfds_01","weds_02","adwews_03","adsew._04"这些,其它或许是隐藏的文件,我怎样把"dfds_01","weds_02","adwews_03","adsew._04"挑选出来呢
解决方案七:
用正则:varresult=list.Where(x=>Regex.IsMatch(x,@"w+_d+"));
解决方案八:
varresult=list.Where(x=>Regex.IsMatch(x,@"w+_d+"));请问list这个位置是没经过原来的数组吗
解决方案九:
引用7楼zuiyizhilian的回复:
varresult=list.Where(x=>Regex.IsMatch(x,@"w+_d+"));请问list这个位置是没经过原来的数组吗
varlist=newstring[]{"dfds_01","weds_02","adwews_03","desktop","folder","adsew._04","abc"};//abc不被匹配,只匹配字母+下划线+数字的
解决方案十:
非常感谢,但你写这个语句匹配汉字+下划线+数字吗?
解决方案十一:
引用5楼zuiyizhilian的回复:
二楼的varlist=newstring[]{"dfds_01","weds_02","adwews_03","desktop","folder","adsew._04"};varfilter=newstring[]{"desktop","folder"};varresult=list.Except(filter);固然好理解,而且简……
描述还是不够清楚,你到底要取什么
解决方案十二:
"zuiyizhilian"这位高手,它写这个正是我想要的,正合我意,但能否匹配汉字+下划线+数字
解决方案十三:
[^u4E00-u9FA5]+_d+
解决方案十四:
对不起版主我弄清楚就不啰嗍了varresult=list.Where(x=>Regex.IsMatch(x,@"[^u4E00-u9FA5]+_d+"));是这样吗?
解决方案十五:
引用11楼zuiyizhilian的回复:
"zuiyizhilian"这位高手,它写这个正是我想要的,正合我意,但能否匹配汉字+下划线+数字
[u4E00-u9FA5_d]+stringnn="凯撒的律师dfds_01费阿司法局的是费尽了_看首付就134555_56666";Regexreg2=newRegex(@"[u4E00-u9FA5_d]+");boolmn=reg2.IsMatch(nn);
解决方案:
引用9楼zuiyizhilian的回复:
非常感谢,但你写这个语句匹配汉字+下划线+数字吗?
varresult=list.Where(x=>Regex.IsMatch(x,@"^w+.?_d+$")).ToArray();
解决方案:
.NET正则中w就包含了数字字母汉字和下划线了
解决方案:
非常感谢
解决方案:
督察说的对!