简体   繁体   中英

string.join to append with some count and take rest to newline

I am using string.join appending many data which is separated by comma.If we have more than 50,only first 10 are visible and others are not visible.It will exit the screen size.I want to display the data with some count in string within screen.

_validatonDictionary.AddError(string.Empty, string.Join(",", findduplicate) + "-Settlement POD," + string.Join(",", finddupl) + "-Ded are duplicate PODS");

"findduplicate" and "finddupl" is the list which consist of more than 100 item.I want to diplay maximum 10 one after other

You can use Ceiling

//Calculating number of loops to run
int ceilingLimit = 10;
int iCount = finddupl.Count() / ceilingLimit + (finddupl.Count() % ceilingLimit != 0 ? 1 : 0);;
for (int iLoopCount = 0; iLoopCount < iCount; ++iLoopCount)
{
     int iRecordCount = finddupl.Count() >= ceilingLimit ? ceilingLimit : finddupl.Count();
     var currentDupls = finddupl.Take(iRecordCount).ToList();
     _validatonDictionary.AddError(string.Empty, string.Join(",", findduplicate) + "-Settlement POD," + string.Join(",", currentDupls) + "-Ded are duplicate PODS");
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM