使用*进行过滤,这将限制以Null开头的所有值? [英] Filter with * which will restrain all values that starts with Null?
问题描述
我有以下代码扩展了我的过滤器功能,允许我搜索多个Zip代码。防爆。 (1254,125,145,1455)
if (Post_Code_PAR!= null )
{
String [] PostCode_Array = Post_Code_PAR.Split(' ,');
query = 来自 p 查询其中 PostCode_Array.Contains(p.Post_Code)选择 p;
}
我想扩展这段代码,如果我给它类似于(0 *)的东西,它会找到以0开头的邮政编码。如果我给它123 *,它会给我所有以123开头的邮政编码。非常感谢。
也试过这个:
String [] PostCode_Array = 来自 p Post_Code_PAR.Split('' ,')选择 字符串 .Format ( ^ {0} $,p.Replace( , @ \ d跨度>));
query = 来自 p 查询其中 PostCode_Array.Any(pattern = > Regex.IsMatch(p.Post_Code,pattern)) select p;
但我收到此错误:
错误7类型'System.Collections.Generic .IEnumerable< string> 不能隐式转换为'string []'。已经存在显式转换。(也许你错过了演员。)
,p.Replace( , @ \d));
query = 来自 p 查询其中 PostCode_Array.Any(pattern = > Regex.IsMatch(p.Post_Code,pattern)) select p;
但我收到此错误:
错误7类型'System.Collections.Generic .IEnumerable< string> 不能隐式转换为'string []'。已经存在显式转换。(也许你错过了演员。)
怎么样:
字符串 [] PostCode_Array = ( 来自 p Post_Code_PAR.Split(' ,')
选择 字符串 .Format( ^ {0}
,p.Replace( , @ \ d )))
.ToArray();
?
I have the following code which extends my filter functionality to allow me to search for more than one Zip-code. Ex. (1254,125,145,1455)
if (Post_Code_PAR != null)
{
String[] PostCode_Array = Post_Code_PAR.Split(',');
query = from p in query where PostCode_Array.Contains(p.Post_Code) select p;
}
I want to extend this code in a way that if I give it something like (0*) it will find zip codes which starts with 0. If I give it 123* it will give me all zip codes which starts with 123. Thanks a lot.
also tried this:
String[] PostCode_Array = from p in Post_Code_PAR.Split(',') select String.Format("^{0}$", p.Replace("", @"\d"));
query = from p in query where PostCode_Array.Any(pattern => Regex.IsMatch(p.Post_Code, pattern)) select p;
But Iam getting this error:
Error 7 The type 'System.Collections.Generic.IEnumerable <string> "can not be implicitly converted to' string [] '. There is already an explicit conversion exists. (Maybe you missing a cast.)
", p.Replace("", @"\d")); query = from p in query where PostCode_Array.Any(pattern => Regex.IsMatch(p.Post_Code, pattern)) select p;
But Iam getting this error:
Error 7 The type 'System.Collections.Generic.IEnumerable <string> "can not be implicitly converted to' string [] '. There is already an explicit conversion exists. (Maybe you missing a cast.)
What about:
String[] PostCode_Array = (from p in Post_Code_PAR.Split(',') select String.Format("^{0}
", p.Replace("", @"\d"))) .ToArray();
?
这篇关于使用*进行过滤,这将限制以Null开头的所有值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!