/// <summary>
/// 获取字符列表
/// </summary>
/// <param name="source"></param>
/// <returns></returns>
public static List<string> GetStringList(this string source)
{
List<string> list = new List<string>();
if (!string.IsNullOrEmpty(source))
{
string[] temps = source.Split(';');
foreach (string item in temps)
{
if (!string.IsNullOrEmpty(item))
{
list.Add(item);
}
}
}
return list;
}
通过获取的值source对其进行;的分割,把分割到的每条数据装到temps的数组中,随后把数组里的数据进行循环判断,对于非NULL与非empty的值进行累加的装入,最后返回的list里面存在这多条数据,在调用时用GetStringList()[] 。()里装需切割的字段,[]装数字选取(eg:(Image)[0], (Image)[1])
/// <summary>
/// 获取数字列表
/// </summary>
/// <param name="source"></param>
/// <returns></returns>
public static List<int> GetIntList(this string source)
{
List<int> ids = new List<int>();
if (!string.IsNullOrEmpty(source))
{
string[] temps = source.Split(';');
foreach (string item in temps)
{
if (!string.IsNullOrEmpty(item))
{
ids.Add(Convert.ToInt32(item));
}
}
}
return ids;
}
数字列表的获取与字符列表的解释类似
后台Split分割
var str = Info.Split(new string[] { "." }, StringSplitOptions.RemoveEmptyEntries)[1];(info为需切割的字段)