C# 将数组、集合、可枚举类型转换成逗号分隔的字符串(String.Join)
C# 将数组、集合、可枚举类型转换成逗号分隔的字符串(String.Join)
C# Code:
public const int MAX_KEYWORDS = 20;
string searchInput="123,3456,347,234,5612,345,234,52,345,2as,fg,wert,w,ert,w,ert,24,56,347,";
public const int MAX_KEYWORDS = 20;
string searchInput="123,3456,347,234,5612,345,234,52,345,2as,fg,wert,w,ert,w,ert,24,56,347,";
//分解关键字,去掉空的关键字
string[] items = searchInput.Split(new char[] { char.Parse(",") }, StringSplitOptions.RemoveEmptyEntries);
//去重复关键词
items = items.Distinct().ToArray();
if (items.Length > MAX_KEYWORDS)
{
string[] copy = new string[MAX_KEYWORDS];
Array.Copy(items, 0, copy, 0, MAX_KEYWORDS);//复制数组
//C# 将数组、集合、可枚举类型转换成逗号分隔的字符串(String.Join)
return String.Join(",", copy);
}
else
{
return String.Join(",", items);
}
//来源:C/S框架网 | www.csframework.com | QQ:23404761
string[] items = searchInput.Split(new char[] { char.Parse(",") }, StringSplitOptions.RemoveEmptyEntries);
//去重复关键词
items = items.Distinct().ToArray();
if (items.Length > MAX_KEYWORDS)
{
string[] copy = new string[MAX_KEYWORDS];
Array.Copy(items, 0, copy, 0, MAX_KEYWORDS);//复制数组
//C# 将数组、集合、可枚举类型转换成逗号分隔的字符串(String.Join)
return String.Join(",", copy);
}
else
{
return String.Join(",", items);
}
//来源:C/S框架网 | www.csframework.com | QQ:23404761
版权声明:本文为开发框架文库发布内容,转载请附上原文出处连接
NewDoc C/S框架网