| 我以前写sms时候的C#短信息切字代码,超过70的按照两条发送,类推,给你,自己来看!  |
>>
|
mingziweb 于 2006-6-29 15:12:33 加贴在 .NET技术 ←返回版面:

using System;
using System.IO ;
using System.Text ;
using System.Collections ;
namespace Test
{
/// <summary>
/// Class1 的摘要说明。
/// </summary>
class Class1
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main(string[] args)
{
string content = "将所有的中英文混合输出,将所有的中英文混合输出,将所有的中英文混合输出,将所有的中英文混合输出,在Windows 2003 Server 上,发现他们都是用两个字节表示,中文和英文都是按照两个字节来计算的,Hello,my Friend!我的一个测试开始了,请看看运行的结果如何" ;
Console.Write( GetText(content) ) ;
ArrayList arrText = GetPocketText(content) ;
for( int i=0 ; i<=arrText.Count-1; i++)
{
Console.Write(arrText[i].ToString()) ;
}
}
private static ArrayList GetPocketText( string text )
{
ArrayList newText ;
//这里的数字可以自己改,10表示是10个汉字,你可以改成你的70,就是70个汉字。
newText = GetPocketText( text , 10 ) ;
return newText ;
}
private static ArrayList GetPocketText( string text , int length )
{
ArrayList arrOutputText = new ArrayList() ;
int textLength = text.Length ;
float countLength = (float)textLength/(float)length ;
int count = (int)Math.Ceiling( (double)countLength ) ;
if( textLength>length )
{
for(int i=0 , j=0 ; i<=count-1 ; i++,j+=length )
{
if(i==count-1)
{
arrOutputText.Add( text.Substring(j) ) ;
}
else
{
arrOutputText.Add( text.Substring(j,length) ) ;
}
//if(i<count-1)
//{
//arrOutputText.Add("#####") ;
//}
}
}
else
{
arrOutputText.Add( text ) ;
}
return arrOutputText ;
}
}
}
计算机世界开发者俱乐部 http://dev-club.esnai.com
你觉得本精华贴如何? 请给本精华贴打分

|
|
* 游客不能打分。
|
|
|

-
请教如何实现这一功能短信按70个字切分开来,超过70汉字就按两条短信 - boy79 2006-6-18 20:09:12 [ID:2571462 点击:1687] (53 Bytes) (4)
-
我以前写sms时候的C#短信息切字代码,超过70的按照两条发送,类推,给你,自己来看! - mingziweb 2006-6-29 15:12:33 [ID:2572025 点击:348] (1751 Bytes) (0)
-
iq club <联结> - justouch 2006-6-19 12:10:10 [ID:2571473 点击:1593] (7 Bytes) (0)
-
这个应该是短信网关做的事情 - 掉掉 2006-6-19 7:41:25 [ID:2571466 点击:1507] (34 Bytes) (1)