C# 字符串按长度转泛型List<string> 的实现 先创建一个对象,有ID和Re字段;然后实例化List<T>;最后循环长字符串添加到集合中! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 这个东西,直接遍历string中的字符,设置各起始位置,用substring取就是了 int i=0; List<string> lst = new List<string>(); string substr="长字符串"; string str="40的字符串"; while(substr.Length>0) { if(substr.Length>40) { str = substr.Substring(i * 40, (i + 1) * 40); substr = substr.Substring((i + 1) * 40); } else { str = substr; substr = string.Empty; } lst.Add(str); }把List类型换掉即可。id=i; 还是自己搞了,想看看有没有更简便的方法、还是得自己根据逻辑截取。 int j = 1; // ComUwPolicy uw = new ComUwPolicy(); // int a = modPage.DataContent.Trim().ToString().Length % 40; // string str_temp = "";//记录截取的字符串 // for (int i = 0; i < modPage.DataContent.Trim().ToString().Length; i++) // { // str_temp = str_temp + modPage.DataContent.Trim().Substring(i, 1); // if ((i % 40) == 0 && i > 0) // { // UwEngage enage = new UwEngage(); // enage.ClauseCode = "T0001"; // enage.ClauseName = "特别约定"; // enage.Clauses = str_temp; // enage.SerialNo = j; // j++; // str_temp = ""; // uw.Engages.Add(enage); // } // } // if (modPage.DataContent.Trim().Length % 40 != 0) // { // UwEngage enage = new UwEngage(); // enage.ClauseCode = "T0001"; // enage.ClauseName = "特别约定"; // enage.Clauses = modPage.DataContent.Trim().Substring(modPage.DataContent.Length - modPage.DataContent.Length % 40, modPage.DataContent.Length % 40); // enage.SerialNo = j; // uw.Engages.Add(enage); // } vs2012不支持async,await? 结束进程 急救,timer里能否用热键?兄弟先谢谢各位了, VS2010调试.Net源码无法查看变量值 vb.net 通信接收不到数据 C# 实现目录权限问题 新手提问:怎样更改Web项目存放位置? 自定义控件重绘问题! 请教 全屏的 程序怎么写 C#新手来问简单问题:如何从text控件中取得数字的值? datagridview 一键保存 winform自定义控件 经常丢失列
List<string> lst = new List<string>();
string substr="长字符串";
string str="40的字符串";
while(substr.Length>0)
{
if(substr.Length>40)
{
str = substr.Substring(i * 40, (i + 1) * 40);
substr = substr.Substring((i + 1) * 40);
}
else
{
str = substr;
substr = string.Empty;
}
lst.Add(str);
}把List类型换掉即可。id=i;
// ComUwPolicy uw = new ComUwPolicy();
// int a = modPage.DataContent.Trim().ToString().Length % 40;
// string str_temp = "";//记录截取的字符串
// for (int i = 0; i < modPage.DataContent.Trim().ToString().Length; i++)
// {
// str_temp = str_temp + modPage.DataContent.Trim().Substring(i, 1);
// if ((i % 40) == 0 && i > 0)
// {
// UwEngage enage = new UwEngage();
// enage.ClauseCode = "T0001";
// enage.ClauseName = "特别约定";
// enage.Clauses = str_temp;
// enage.SerialNo = j;
// j++;
// str_temp = "";
// uw.Engages.Add(enage);
// }
// }
// if (modPage.DataContent.Trim().Length % 40 != 0)
// {
// UwEngage enage = new UwEngage();
// enage.ClauseCode = "T0001";
// enage.ClauseName = "特别约定";
// enage.Clauses = modPage.DataContent.Trim().Substring(modPage.DataContent.Length - modPage.DataContent.Length % 40, modPage.DataContent.Length % 40);
// enage.SerialNo = j;
// uw.Engages.Add(enage);
// }