A long time ago, I wrote a mobile phone search query, which involves the separation of mobile phone types and models.
Some people asked this question a long time ago, so I wrote a note to release the draft of this function, and wrote some of these instructions.
Function description, such as search input: Nokia N95, will be split into brand: Nokia model: N95
For mobile phone data collection, you can also use this function to separate the brand name and model.
SetSearchKey ("Nokia N95", out Nokia, out N95 );
The function code is as follows:
Protected void SetSearchKey (string keyword, out string goodsName, out string goodsModel)
{
Keyword = keyword. ToLower (). Trim ();
If (keyword. Contains ("") // with spaces, separate
{
GoodsName = keyword. Split ('') [0]. Trim ();
GoodsModel = keyword. Split ('') [1]. Trim ();
}
Else if (Regex. match (keyword, @ "^ [\ u4E00-\ u9FA5] + [\ w \ d] + "). success) // starts with a Chinese character, including English and separated
{
GoodsName = Regex. Match (keyword, @ "^ ([\ u4E00-\ u9FA5] +) [\ w \ d] +"). Groups [1]. Value;
GoodsModel = keyword. Replace (goodsName, string. Empty );
}
Else
{
String [] keys = new string [] {"nec", "lg", "vk", "cect "};
For (int I = 0; I <keys. Length; I ++)
{
If (keyword. IndexOf (keys [I]) = 0)
{
GoodsName = keys [I];
GoodsModel = keyword. Replace (goodsName, string. Empty );
Return;
}
}
GoodsName = keyword;
GoodsModel = keyword;
}
}