.NET中Split分割用法

实例代码:
/// <summary>
/// 截取格位置格号
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Window_SJ_Close(object sender, WindowCloseEventArgs e)
{
string thtext = string.Empty;//格位置
string idtext = string.Empty;//格号
string[] array = hfGridId.Text.TrimEnd(',').ToString().Split(',');//取到值去掉尾部逗号,按逗号分割
for (int j = 0; j < array.Length; j++)
{
string[] ht= array[j].TrimEnd('|').ToString().Split('|');//内部按|分割后赋值
thtext += ht[0]+"</br>";
idtext += ht[1]+",";
}
hfGridId.Text = idtext;
 
MessageBox_Ext("上架格号为:</br>" + thtext);
}
 
调用: 
//判断格容量是否充足
string[] array = hfGridId.Text.TrimEnd(',').ToString().Split(',');//调用分割出来的格号按逗号分割
for (int j = 0; j < array.Length; j++)
{
tbl_Grids_Info GridInfo = tbl_Grids_Info.GetModel(int.Parse(array[j]));
int restCnts = GridInfo.CAPACITY - GridInfo.FILECNTS;
//判断格子是否还有剩余容量
if (restCnts <= 0)
{
MessageBox_Ext("该档案格现有容量已满,请更换档案格");
return;
}
//上架数量小于格子剩余容量,则把上架总数量赋值给上架循环次数
int loopCount = 0;//上架循环次数
if (checklist.Count < restCnts)
{
loopCount = checklist.Count;
}
//不足则把剩余容量赋值给上架循环次数
else
{
loopCount = restCnts;
}
posted @ 2017-04-24 16:11  Abraham2017  阅读(804)  评论(0编辑  收藏  举报