我要实现的功能是这样的:
有一段文字,我要把它以每300字为一段截取出来,然后赋给一个数组。也就是截完300字后,在从后边的文字中继续截取300字,以此类推,直到截完为止。
给出详细代码,不胜感激。
有一段文字,我要把它以每300字为一段截取出来,然后赋给一个数组。也就是截完300字后,在从后边的文字中继续截取300字,以此类推,直到截完为止。
给出详细代码,不胜感激。
解决方案 »
- 关于带搜索的分页的存储过程!
- .net实现注册的时候检查用户名和邮箱是否已存在!
- dropdownlist数据绑定的问题
- asp页面跟asp.net页面可以互相跳转吗?
- 如何在TextBox下输入完敲回车引发特定的按扭事件!先谢谢各位了!
- 请问如何不关闭原来页面而打开新的web页面
- 请问这个xml文件可以放在这treeview里吗? 送分分[100]
- 检测到有潜在危险的 Request.Form 值的问题
- 我把原来的一个程序拷贝到另外一个目录下,进行编译调式,修改后还是原来目录下的内容在改变
- 很急很急~~~!!我的一个定制控件调用系统字体的问题?(跪救~~~~~~~!!!)在线等待~!
- 如何实现这种MVC结构?
- JS为何不能滚动了,静态的时候还可以滚动的!
List<String> lst=new List<String>();
while(s.Length>300) //300字符长度
{
lst.Add(s.SubString(0,300));
s=s.SubString(300);
}
lst.Add(s);
List<String> lst=new List<String>();
while(s.Length>300) //300字符长度
{
lst.Add(s.SubString(0,300));
s=s.SubString(300);
}
lst.Add(s);
数组就用for循环撒!
//随机生成一些字符串
byte[] buf = new byte[1000];
(new Random()).NextBytes(buf);
s = new string(System.Text.ASCIIEncoding.ASCII.GetChars(buf));//生成List<string>
List<String> list = new List<String>();
while (s.Length > 300) //300字符长度
{
list.Add(s.Substring(0, 300));
s = s.Substring(300);
}
list.Add(s);//转换成数组
string[] arr = list.ToArray();
public string[] SubStr(string str)
{
int num = str.Length / 3;
if (str.Length%3>0)
{
num= num + 1;
}
string[] strs=new string[num];
for (int i = 0; i < num; i++)
{
if (i == num - 1)
{
strs[i] = str.Substring(i * 3);
}
else
{
strs[i] = str.Substring(i * 3, 3);
}
}
return strs;
}写的不好 将就用吧