[Delphi]字符串拆分

字符串按一个数量拆分 ,我是应用在短信拆分。中英文均认为是2个字符,所以输入参数mText为WideString类型。

可以这么理解 string,widestring

============

string 单位:1char

widestring 单位:2char

string '我们ss' 长度为6

widestring '我们ss' 长度为4

============

函数名 WrapWideString

输入:mText 短信内容 mLength 短信设定长度

输出:整段内容以#13#10拆分

============

function WrapWideString(mText:WideString; mLength : Integer): String;
var
  J:Integer;
begin
  Result:
='';
  
while Length(mText) > mLength do
  
begin
    J :
= Ord(ByteType(mText, mLength) = mbLeadByte);
    Result :
= Result + #13#10 + Copy(mText, 1, mLength - J);
    Delete(mText, 
1, mLength - J);
  
end;
   Result :
= Result + #13#10 + Copy(mText, 1, mLength);
   Delete(Result, 
12);
end;
posted @ 2009-07-17 13:46  德罗德  阅读(622)  评论(0编辑  收藏  举报