要求取得的字符每140个字节算一条记录,如果超分为两条记插入到数据库中
这是一个朋友给我代码,但运行后错误提示:索引和长度必须引用该字符串内的位置。参数名: length
代码如下:
string instr=xxxx;
int xs=instr.Length/160if(xs>1)
{
conn.open();
for(int i=0;i<xs;i++)
{
string upstr=instr.Substring(i*160,(i+1)*160);
cmd.commandtext="insert ...."
cmd.....
}
}
else
{
cmd.comm...直接执行插入
}
这是一个朋友给我代码,但运行后错误提示:索引和长度必须引用该字符串内的位置。参数名: length
代码如下:
string instr=xxxx;
int xs=instr.Length/160if(xs>1)
{
conn.open();
for(int i=0;i<xs;i++)
{
string upstr=instr.Substring(i*160,(i+1)*160);
cmd.commandtext="insert ...."
cmd.....
}
}
else
{
cmd.comm...直接执行插入
}
{
for(int i=0;i<xs;i++)
{
string upstr=instr.Substring(i*160,160);
}
}
后面一个是长度
ArrayList SendSmsInfo = new ArrayList();
while (System.Text.Encoding.Default.GetByteCount(aaa) > 140)
{
string SendStr = aaa.Substring(0, 70);
aaa= aaa.Remove(0, 70);
while (System.Text.Encoding.Default.GetByteCount(SendStr) < 140)
{
SendStr = SendStr + aaa[0];
aaa = aaa.Remove(0, 1);
}
if (System.Text.Encoding.Default.GetByteCount(SendStr) > 140)
{
aaa=aaa.Insert(0, SendStr[SendStr.Length - 1].ToString());
SendStr = SendStr.Remove(SendStr.Length - 1, 1);
}
SendSmsInfo.Add(SendStr );
}
if (aaa != "" && aaa != null)
{
SendSmsInfo.Add(aaa );
}
for (int i = 0; i < SendSmsInfo.Count; i++)
{
Console.WriteLine(" Content:"+sms[1]);
}
Console.ReadLine();